public static byte[] encrypt(string ascii_text)
{
if (ascii_text == null) return new byte[] { 0 };
byte[] ba = new byte[ascii_text.Length + 1];
ba[0] = (byte)ascii_text.Length;
int offset = 167;
char[] ca = ascii_text.ToCharArray();
for (int i = 0; i < ascii_text.Length; i++)
{
offset += 12;
int b = (int)ca[i];
b += offset % 256;
b = b % 256;
ba[i + 1] = (byte)b;
}
if (decrypt(ba) != ascii_text) throw new ApplicationException();
return ba;
}
public static string decrypt(byte[] ba)
{
StringBuilder sb = new StringBuilder(ba[0]);
int offset = 167;
for (int i = 0; i < ba[0]; i++)
{
offset += 12;
}
for (int i = 0; i < ba[0]; i++)
{
int b = ba[ba[0] - i];
b = b - offset % 256;
if (b < 0) b += 256;
sb.Insert(0, new char[] { (char)b });
offset -= 12;
}
return sb.ToString();
}
{
if (ascii_text == null) return new byte[] { 0 };
byte[] ba = new byte[ascii_text.Length + 1];
ba[0] = (byte)ascii_text.Length;
int offset = 167;
char[] ca = ascii_text.ToCharArray();
for (int i = 0; i < ascii_text.Length; i++)
{
offset += 12;
int b = (int)ca[i];
b += offset % 256;
b = b % 256;
ba[i + 1] = (byte)b;
}
if (decrypt(ba) != ascii_text) throw new ApplicationException();
return ba;
}
public static string decrypt(byte[] ba)
{
StringBuilder sb = new StringBuilder(ba[0]);
int offset = 167;
for (int i = 0; i < ba[0]; i++)
{
offset += 12;
}
for (int i = 0; i < ba[0]; i++)
{
int b = ba[ba[0] - i];
b = b - offset % 256;
if (b < 0) b += 256;
sb.Insert(0, new char[] { (char)b });
offset -= 12;
}
return sb.ToString();
}