ID:183176
 
I am trying to create my own encryption by replacing characters with other characters. But after trying Replace() I realized if I were to replace Z with A when I goto replace A it will get changed again. I was wondering is their a way I could Replace text for more than 1 character at a time so i wouldn't have one Z changed to A. My second question is how could I make it so that I can Replace Letter Z with A but when I replace letter A it doesn't get changed to the letter that I replace A with.
There are alot of encryption tool in the System.Security.Cryptography namespace that you could use. Not to be mean, but I doubt you could come up with better encryption then whats in there.

http://msdn2.microsoft.com/en-us/library/ system.security.cryptography.aspx
In response to Soldierman
Yeah, you will never make something better than what's already there, but it could be fun to try and learn.

And to replace multiple letters, just loop it, and to keep it from replacing more, save the original string and read from that as you replace in a new string.
In response to Kunark
Thanks Soilderman and Kunark
In response to Upinflames
So i followed both soilderman and Kunark's instructions to use the Cryptography Microsoft provides. I then created a DLL following one of their demos. I compiled it. Then I try to use it in my application and it says it can't find the procedure. I included the DLL to the project. Here is the code, if it's not to do with code let me know:
using Encryption;

Encrypt a = new Encrypt();
a.Encrypt(a, b);

For me DLL's never seem to work :/
In response to Upinflames
Haha, you might want to learn about encryption before attempting it. It's nothing like it is on BYOND. Here is my functional encryption/decryption class in C#:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;

namespace Rabid_Util
{
/// <summary>
/// This utility is used to encrypt/decrypt strings of text. This class requires the Debugger to work.
/// </summary>
public static class CryptUtil
{
/// <summary>
/// Encrypts a text string using the values specified.
/// </summary>
/// <param name="msg">The text string to encrypt.</param>
/// <param name="password">Password used to encrypt the packet. Can be any ASCII string.</param>
/// <param name="salt">Any ASCII string.</param>
/// <param name="hashname">The hash algorithm used to generate a password. Possible values are "SHA1" for secure-but-slower encryption and "MD5" for less secure but safer encryption.</param>
/// <param name="iterations">How many times to regenerate a password. One or two is secure enough.</param>
/// <param name="vector">Initialization Vector (or IV). This value is required to encrypt the first block of plaintext data. For RijndaelManaged class, IV must be exactly 16 ASCII characters long.</param>
/// <param name="keysize">The size of the encryption key in bits. Allowed values are: 128, 192, 256. Longer keys are more secure than shorter keys.</param>
/// <returns>An encrypted text string.</returns>
public static string Encrypt(string msg, string password, string salt, string hashname, int iterations, string vector, int keysize)
{
if (Errors.UtilErrors.CheckCrypt(vector, hashname, keysize))
{
return msg;
}
byte[] bmsg = Encoding.UTF8.GetBytes(msg);
byte[] bsalt = Encoding.ASCII.GetBytes(salt);
byte[] bvector = Encoding.ASCII.GetBytes(vector);
PasswordDeriveBytes pass = new PasswordDeriveBytes(password, bsalt, hashname, iterations);
byte[] bkeysize = pass.GetBytes(keysize / 8); //specified in bytes instead of bits

RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC; //Cypher Block Chaining mode
ICryptoTransform encrypt = symmetricKey.CreateEncryptor(bkeysize, bvector);

MemoryStream memStream = new MemoryStream();
CryptoStream cryptStream = new CryptoStream(memStream, encrypt, CryptoStreamMode.Write);
cryptStream.Write(bmsg, 0, bmsg.Length);
cryptStream.FlushFinalBlock();

byte[] cipherTextBytes = memStream.ToArray();

memStream.Close();
cryptStream.Close();

string cipher = Convert.ToBase64String(cipherTextBytes);

return cipher;
}


/// <summary>
/// Decrypts a text string using the values specified.
/// </summary>
/// <param name="cipher">The text string to decrypt.</param>
/// <param name="password">Password used to encrypt the packet. Can be any ASCII string.</param>
/// <param name="salt">Any ASCII string.</param>
/// <param name="hashname">The hash algorithm used to generate a password. Possible values are "SHA1" for secure-but-slower encryption and "MD5" for less secure but safer encryption.</param>
/// <param name="iterations">How many times to regenerate a password. One or two is secure enough.</param>
/// <param name="vector">Initialization Vector (or IV). This value is required to encrypt the first block of plaintext data. For RijndaelManaged class, IV must be exactly 16 ASCII characters long.</param>
/// <param name="keysize">The size of the encryption key in bits. Allowed values are: 128, 192, 256. Longer keys are more secure than shorter keys.</param>
/// <returns>An decrypted text string.</returns>
public static string Decrypt(string cipher, string password, string salt, string hashname, int iterations, string vector, int keysize)
{
if (Errors.UtilErrors.CheckCrypt(vector, hashname, keysize))
{
return cipher;
}
byte[] bcipher = new byte[0];
try { bcipher = Convert.FromBase64String(cipher); }
catch (Exception e) { Debug.Error(2, e.Message + " " + cipher); }
byte[] bsalt = Encoding.ASCII.GetBytes(salt);
byte[] bvector = Encoding.ASCII.GetBytes(vector);
PasswordDeriveBytes pass = new PasswordDeriveBytes(password, bsalt, hashname, iterations);
byte[] bkeysize = pass.GetBytes(keysize / 8); //specified in bytes instead of bits

RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC; //Cypher Block Chaining mode
ICryptoTransform decrypt = symmetricKey.CreateDecryptor(bkeysize, bvector);

MemoryStream memStream = new MemoryStream(bcipher);
CryptoStream cryptStream = new CryptoStream(memStream, decrypt, CryptoStreamMode.Read);


byte[] bmsg = new byte[bcipher.Length];
int decryptedByteCount = cryptStream.Read(bmsg, 0, bmsg.Length);

memStream.Close();
cryptStream.Close();

string msg = Encoding.UTF8.GetString(bmsg, 0, decryptedByteCount);

return msg;
}
}
}
In response to Kunark
Looks to me like you should try to work on more of the basics of C#, before getting involved into more advanced stuff like encryption. Maybe you could get a C# book and work along with it.
In response to Soldierman
I suggest "Mastering Visual C# .NET by Jason Price/Mike Gunderloy". Excellent book. My only gripe about it is that the Security section isn't long enough and it spends too much time trying to teach SQL and XML in later chapters when both would need to be studied well beyond the scope of the book for full understanding.
In response to Kunark
Thanks again everyone, I guess I should get a book. From when I started until now I have only searched the thing on the internet, follow a demo then create my own.