Click here to Skip to main content
15,890,690 members
Home / Discussions / C#
   

C#

 
QuestionHow can write Algorithm for the following question? Pin
BUNER28-Aug-15 7:55
BUNER28-Aug-15 7:55 
AnswerRe: How can write Algorithm for the following question? Pin
OriginalGriff28-Aug-15 8:07
mveOriginalGriff28-Aug-15 8:07 
GeneralRe: How can write Algorithm for the following question? Pin
BUNER28-Aug-15 8:29
BUNER28-Aug-15 8:29 
GeneralRe: How can write Algorithm for the following question? Pin
OriginalGriff28-Aug-15 8:36
mveOriginalGriff28-Aug-15 8:36 
GeneralRe: How can write Algorithm for the following question? Pin
BUNER28-Aug-15 10:43
BUNER28-Aug-15 10:43 
GeneralRe: How can write Algorithm for the following question? Pin
OriginalGriff28-Aug-15 22:19
mveOriginalGriff28-Aug-15 22:19 
AnswerRe: How can write Algorithm for the following question? Pin
Eddy Vluggen28-Aug-15 9:14
professionalEddy Vluggen28-Aug-15 9:14 
GeneralRe: How can write Algorithm for the following question? Pin
BUNER28-Aug-15 10:41
BUNER28-Aug-15 10:41 
this is the algorithem

class MainClassForAlgo
{

public static string EncryptString(string Message, string Passphrase)
{
byte[] Results;
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();



MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase));
// Step 2. Create a new TripleDESCryptoServiceProvider object
TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();

// Step 3. Setup the encoder
TDESAlgorithm.Key = TDESKey;
TDESAlgorithm.Mode = CipherMode.ECB;
TDESAlgorithm.Padding = PaddingMode.PKCS7;

// Step 4. Convert the input string to a byte[]
byte[] DataToEncrypt = UTF8.GetBytes(Message);

// Step 5. Attempt to encrypt the string
try {
ICryptoTransform Encryptor = TDESAlgorithm.CreateEncryptor();
Results = Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length);
}
finally
{
// Clear the TripleDes and Hashprovider services of any sensitive information
TDESAlgorithm.Clear();
HashProvider.Clear();
}

// Step 6. Return the encrypted string as a base64 encoded string
return Convert.ToBase64String(Results);
}

public static string DecryptString(string Message, string Passphrase)
{
byte[] Results;
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();


MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase));

// Step 2. Create a new TripleDESCryptoServiceProvider object
TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();

// Step 3. Setup the decoder
TDESAlgorithm.Key = TDESKey;
TDESAlgorithm.Mode = CipherMode.ECB;
TDESAlgorithm.Padding = PaddingMode.PKCS7;
// Step 4. Convert the input string to a byte[]
byte[] DataToDecrypt = Convert.FromBase64String(Message);

// Step 5. Attempt to decrypt the string
try
{
ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();
Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length);
}
finally
{
// Clear the TripleDes and Hashprovider services of any sensitive information
TDESAlgorithm.Clear();
HashProvider.Clear();
}

// Step 6. Return the decrypted string in UTF8 format
return UTF8.GetString( Results );
}

public static void Main(string[] args)
{
// The message to encrypt.
string Msg = "poultry outwits ants";
string Password = "4624d200580677270a54ccff86b9610e";

string EncryptedString = EncryptString("poultry outwits ants", Password);
string DecryptedString = DecryptString(EncryptedString, Password);

Console.WriteLine("Message: {0}",Msg);
Console.WriteLine("Password: {0}",Password);
Console.WriteLine("Encrypted string: {0}",EncryptedString);
Console.WriteLine("Decrypted string: {0}",DecryptedString);
Console.ReadKey();
}
}
QuestionXAML Templates for Win 10 Pin
Don Rolando28-Aug-15 7:39
Don Rolando28-Aug-15 7:39 
AnswerRe: XAML Templates for Win 10 Pin
Evil Iceblock1-Sep-15 19:09
Evil Iceblock1-Sep-15 19:09 
Questionaccess to localdb from different pcs in a lan network Pin
Member 1189642727-Aug-15 7:00
Member 1189642727-Aug-15 7:00 
AnswerRe: access to localdb from different pcs in a lan network Pin
OriginalGriff27-Aug-15 8:10
mveOriginalGriff27-Aug-15 8:10 
GeneralRe: access to localdb from different pcs in a lan network Pin
Member 1189642727-Aug-15 8:18
Member 1189642727-Aug-15 8:18 
GeneralRe: access to localdb from different pcs in a lan network Pin
OriginalGriff27-Aug-15 8:39
mveOriginalGriff27-Aug-15 8:39 
GeneralRe: access to localdb from different pcs in a lan network Pin
Member 1189642727-Aug-15 18:57
Member 1189642727-Aug-15 18:57 
GeneralRe: access to localdb from different pcs in a lan network Pin
OriginalGriff27-Aug-15 22:47
mveOriginalGriff27-Aug-15 22:47 
GeneralRe: access to localdb from different pcs in a lan network Pin
Member 1189642728-Aug-15 1:43
Member 1189642728-Aug-15 1:43 
GeneralRe: access to localdb from different pcs in a lan network Pin
OriginalGriff28-Aug-15 2:02
mveOriginalGriff28-Aug-15 2:02 
GeneralRe: access to localdb from different pcs in a lan network Pin
Member 1189642728-Aug-15 2:19
Member 1189642728-Aug-15 2:19 
GeneralRe: access to localdb from different pcs in a lan network Pin
OriginalGriff28-Aug-15 2:29
mveOriginalGriff28-Aug-15 2:29 
AnswerRe: access to localdb from different pcs in a lan network Pin
Gilbert Consellado27-Aug-15 16:11
professionalGilbert Consellado27-Aug-15 16:11 
GeneralRe: access to localdb from different pcs in a lan network Pin
Member 1189642727-Aug-15 19:05
Member 1189642727-Aug-15 19:05 
GeneralRe: access to localdb from different pcs in a lan network Pin
Gilbert Consellado28-Aug-15 5:46
professionalGilbert Consellado28-Aug-15 5:46 
AnswerRe: access to localdb from different pcs in a lan network Pin
Eddy Vluggen28-Aug-15 2:04
professionalEddy Vluggen28-Aug-15 2:04 
QuestionLooking for Critique of My Answers to Recent C# Multithreading Interview Questions... Pin
clientSurfer26-Aug-15 8:06
professionalclientSurfer26-Aug-15 8:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.