C# text encoder / decoder
Please note that I'm not a professional developer and I might make simple mistakes because of that, I'm also dutch, and 14 years old, so please keep that in mind before you reply. thank you C:
My brother came up with an idea to encode and decode text with a username and a password...
When you encode something you have to decode it with the same username and password again, otherwise it will give you a very strange character text.
We're going to use this for our website, and I thought it might be nice to share this with others!
Here's the DLL file: http://data.bemacizedgaming.com/CSharp_Pauls_CodeSystem.dll
Encode:
public static UInt64[] Encode(string text, string username, string password)
{
// set values for use in method
UInt64 usrnpas = 0;
// convert the values to bytes
Byte[] t = Encoding.ASCII.GetBytes(text);
Byte[] u = Encoding.ASCII.GetBytes(username);
Byte[] p = Encoding.ASCII.GetBytes(password);
// create list for numbers to be added later
List<UInt64> tl = new List<UInt64>();
// convert username and password to UInt64 and * them into usrnpas
UInt64 ui = 0;
UInt64 pi = 0;
foreach (Byte bu in u)
{
ui += Convert.ToUInt64(bu);
}
foreach (Byte bp in p)
{
pi += Convert.ToUInt64(bp);
}
usrnpas = ui * pi;
// multiply all text data by that number and return them all
foreach (Byte tb in t)
{
tl.Add((Convert.ToUInt64(tb) * usrnpas));
}
return tl.ToArray();
}
Decoding:
public static string Decode(string[] textarray, string username, string password)
{
List<ulong> ul = new List<ulong>();
foreach (string s in textarray)
{
ul.Add(Convert.ToUInt64(s));
}
return Decode(ul.ToArray(), username, password);
}
public static string Decode(UInt64[] textarray, string username, string password)
{
// set values for use in method
UInt64 usrnpas = 0;
string endstring = "";
// convert the values to bytes
Byte[] u = Encoding.ASCII.GetBytes(username);
Byte[] p = Encoding.ASCII.GetBytes(password);
// convert username and password to UInt64 and * them into usrnpas
UInt64 ui = 0;
UInt64 pi = 0;
foreach (Byte bu in u)
{
ui += Convert.ToUInt64(bu);
}
foreach (Byte bp in p)
{
pi += Convert.ToUInt64(bp);
}
usrnpas = ui * pi;
// devide everything by the usrnpass and get the string with ASCII
List<byte> bytes = new List<byte>();
foreach (UInt64 i in textarray)
{
try
{
byte s = (byte)(i / usrnpas);
bytes.Add(s);
}
catch
{
return "ERROR";
}
}
endstring = Encoding.ASCII.GetString(bytes.ToArray());
return endstring;
}
If you feel like improving this please reply with your suggestion (: