how to encrypt a string by coding?? | Newbie | | Join Date: Jan 2008
Posts: 4
| | |
please somebody show me the way... ^^
|  | Moderator | | Join Date: Dec 2006 Location: Bangalore ,India
Posts: 7,511
| | | re: how to encrypt a string by coding??
You can try to replace some characters by others and reverse the process to get back the actual string.
| | Moderator | | Join Date: Oct 2006 Location: Australia
Posts: 7,748
| | | re: how to encrypt a string by coding?? Quote:
Originally Posted by idalreadyuse please somebody show me the way... ^^ I don't think there is any one standard way of encrypting text. You should research the subject and determine what your requirements are. Here is a link to help get you started.
|  | Needs Regular Fix | | Join Date: Sep 2007 Location: Wales
Posts: 467
| | | re: how to encrypt a string by coding??
One way i have used...
Pick out each character in a string and return the asci code of the character. have some mathematical fun and then turn it back into a character...
basically some asci swapping.
Works well for personal use.
functions used are
mid()
asc()
chr()
| | Member | | Join Date: Dec 2007
Posts: 41
| | | re: how to encrypt a string by coding??
Killer42 is correct when he says that there is no standard way to encrypt and that you should do some research to find out what would best fit your needs. However, I used to use the below functions (I don’t any more). They are only going to keep the honest people honest. With that said here you go… -
-
Function Decrypt(ByVal TextVal As String) As String
-
Dim x As Integer
-
For x = 1 To Len(TextVal)
-
Mid$(TextVal, x, 1) = Chr(Asc(Mid(TextVal, x, 1)) - 100)
-
Next
-
Decrypt = TextVal
-
End Function
-
-
Function Encrypt(ByVal TextVal As String) As String
-
Dim x As Integer
-
For x = 1 To Len(TextVal)
-
Mid$(TextVal, x, 1) = Chr(Asc(Mid(TextVal, x, 1)) + 100)
-
Next
-
Encrypt = TextVal
-
End Function
I hope this helps
Torgg
| | Member | | Join Date: Dec 2007
Posts: 41
| | | re: how to encrypt a string by coding??
Even better encryption/decryptions. I use this class in my projects and it works great. Symmetric Key Encryption using Rijndael and C# - public class Cryptography
-
{
-
//**********************************************************************
-
//****** Key generated from https://www.grc.com/passwords.htm ******
-
//**********************************************************************
-
private static string sKey = "D41B11724DDD5276F9793EBA4F2DE9F8"; //Can only be 32 characters long
-
-
public static string EncryptString(string InputText)
-
//http://dotnet.org.za/deon/articles/2998.aspx
-
{
-
// We are now going to create an instance of the Rihndael class.
-
System.Security.Cryptography.RijndaelManaged RijndaelCipher = new System.Security.Cryptography.RijndaelManaged();
-
-
// First we need to turn the input strings into a byte array.
-
byte[] PlainText = System.Text.Encoding.Unicode.GetBytes(InputText);
-
-
// We are using salt to make it harder to guess our key using a dictionary attack.
-
byte[] Salt = Encoding.ASCII.GetBytes(sKey.Length.ToString());
-
-
// The (Secret Key) will be generated from the specified password and salt.
-
System.Security.Cryptography.PasswordDeriveBytes SecretKey = new System.Security.Cryptography.PasswordDeriveBytes(sKey, Salt);
-
-
// Create a encryptor from the existing SecretKey bytes.
-
// We use 32 bytes for the secret key
-
// (the default Rijndael key length is 256 bit = 32 bytes) and
-
// then 16 bytes for the IV (initialization vector),
-
// (the default Rijndael IV length is 128 bit = 16 bytes)
-
System.Security.Cryptography.ICryptoTransform Encryptor = RijndaelCipher.CreateEncryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));
-
-
// Create a MemoryStream that is going to hold the encrypted bytes
-
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
-
-
// Create a CryptoStream through which we are going to be processing our data.
-
// CryptoStreamMode.Write means that we are going to be writing data
-
// to the stream and the output will be written in the MemoryStream
-
// we have provided. (always use write mode for encryption)
-
System.Security.Cryptography.CryptoStream cryptoStream = new System.Security.Cryptography.CryptoStream(memoryStream, Encryptor, System.Security.Cryptography.CryptoStreamMode.Write);
-
-
// Start the encryption process.
-
cryptoStream.Write(PlainText, 0, PlainText.Length);
-
-
// Finish encrypting.
-
cryptoStream.FlushFinalBlock();
-
-
// Convert our encrypted data from a memoryStream into a byte array.
-
byte[] CipherBytes = memoryStream.ToArray();
-
-
// Close both streams.
-
memoryStream.Close();
-
cryptoStream.Close();
-
-
// Convert encrypted data into a base64-encoded string.
-
// A common mistake would be to use an Encoding class for that.
-
// It does not work, because not all byte values can be
-
// represented by characters. We are going to be using Base64 encoding
-
// That is designed exactly for what we are trying to do.
-
string EncryptedData = Convert.ToBase64String(CipherBytes);
-
-
// Return encrypted string.
-
return EncryptedData;
-
}
-
-
public static string DecryptString(string InputText)
-
{
-
System.Security.Cryptography.RijndaelManaged RijndaelCipher = new System.Security.Cryptography.RijndaelManaged();
-
-
byte[] EncryptedData = Convert.FromBase64String(InputText);
-
byte[] Salt = Encoding.ASCII.GetBytes(sKey.Length.ToString());
-
-
System.Security.Cryptography.PasswordDeriveBytes SecretKey = new System.Security.Cryptography.PasswordDeriveBytes(sKey, Salt);
-
-
// Create a decryptor from the existing SecretKey bytes.
-
System.Security.Cryptography.ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));
-
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(EncryptedData);
-
-
// Create a CryptoStream. (always use Read mode for decryption).
-
System.Security.Cryptography.CryptoStream cryptoStream = new System.Security.Cryptography.CryptoStream(memoryStream, Decryptor, System.Security.Cryptography.CryptoStreamMode.Read);
-
-
// Since at this point we don't know what the size of decrypted data
-
// will be, allocate the buffer long enough to hold EncryptedData;
-
// DecryptedData is never longer than EncryptedData.
-
byte[] PlainText = new byte[EncryptedData.Length];
-
-
// Start decrypting.
-
int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length);
-
-
memoryStream.Close();
-
cryptoStream.Close();
-
-
// Convert decrypted data into a string.
-
string DecryptedData = Encoding.Unicode.GetString(PlainText, 0, DecryptedCount);
-
-
// Return decrypted string.
-
return DecryptedData;
-
}
-
}
I hope this is even more helpfull,
Torgg
|  | Site Addict | | Join Date: Nov 2007 Location: Zamboanga City, Philippines
Posts: 861
| | | re: how to encrypt a string by coding??
Hello All
Check out my code on encryption/decryption: click me
Rey Sean
|  | Similar Visual Basic 4 / 5 / 6 bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,533 network members.
|