Code:
public class ASCIIM
{
public byte[] Bytes;
public byte[] Keys;
public int KeyLength
{
get { return Keys.Length - 2; }
}
public void GetBytes(string String)
{
byte[] bytes = new byte[String.Length];
bytes = Encoding.ASCII.GetBytes(String);
for (int i = 0; i < bytes.Length; i++)
{
for (int u = 0; u < Keys.Length; u++)
{
if (u < KeyLength)
{
int key = (int)Keys[u] ^ (int)Keys[u + 1] + ((int)Keys[u + 1] ^ (int)Keys[u]);
bytes[i] += (byte)key;
}
else
u = Keys.Length + 1;
}
}
Bytes = bytes;
}
public string Decode()
{
byte[] bytes = Bytes;
for (int i = 0; i < Bytes.Length; i++)
{
for (int u = 0; u < Keys.Length; u++)
{
if (u < KeyLength)
{
int key = (int)Keys[u] ^ (int)Keys[u + 1] + ((int)Keys[u + 1] ^ (int)Keys[u]);
bytes[i] -= (byte)key;
}
else
u = Keys.Length + 1;
}
}
return Encoding.ASCII.GetString(Bytes);
}
public string GetString()
{
string retstring = "";
for (int i = 0; i < Bytes.Length; i++)
{
retstring += Bytes[i] + " ";
}
return retstring;
}
}
Example:
Code:
ASCIIM ascii = new ASCIIM();
ascii.Keys = new byte[]
{
1, 2, 1, 2, 1, 2
};
ascii.GetBytes("Hello World!");
Console.WriteLine(ascii.GetString());//Writing our bytes.
Console.WriteLine(Encoding.ASCII.GetString(ascii.Bytes));//Writing decoding bytes without keys.
Console.WriteLine(ascii.Decode());//Decoding and writing the decoded bytes.
Code:
92 121 128 128 131 52 107 131 134 128 20 53 \y???4k???x5 Hello World!






