- Joined
- Feb 19, 2008
- Messages
- 1,055
- Reaction score
- 492
So I was browsing 4chan, and somehow this code ended up in my text editor.
This code is written for the D programming language. If you don't know what D is, long story short: C++ with Garbage Collection (optionally removed @nogc) and no enforced backwards compatibility with C so it's a beautiful and quite powerful language. Facebook is investing heavily in D, worth a look. No need to obfuscate your already terrible C#, becomes compiled into native code.
Anyway back to 4chan.
~ Moogly
P.S. If you don't know what this is for, don't worry, I leave this here for those who love this kind of thing, and for future developers who may need it. Maybe next time as I browse through 4chan more code will pop up into my editor again.
usage:
Btw you can paste all this code in 1 file, just put main @ the very bottom.
PPS:
Screenshot of it working!
PPPS:
TUNNEL SNAKES RULE!
Code:
import std.stdio;
import std.math;
/// Summary:
/// Provides Base64 encoding and decoding.
///
class base64Encoding
{
/// Summary:
/// Encodes and integer to a Base64 string.
public static string Encode(int i)
{
try
{
string s = "";
for (int x = 1; x <= 2; x++)
{
s ~= cast(char)(cast(byte)(64 + (i >> 6 * (2 - x) & 0x3f)));
}
return s;
}
catch
{
return "";
}
}
/// Summary:
/// Decodes a Base64 string to an integer.
public static int Decode(string s)
{
char[] val = s.dup;
return Decode(val);
}
/// Summary:
/// Decodes a Base64 char array to an integer.
public static int Decode(char[] val)
{
try
{
int intTot = 0;
int y = 0;
for(int x = (val.length - 1); x >= 0; x--)
{
int intTmp = cast(int)(cast(byte)val[x] - 64);
if (y > 0)
{
intTmp = intTmp * cast(int)(pow(64, y));
}
intTot += intTmp;
y++;
}
return intTot;
}
catch
{
return -1;
}
}
}
This code is written for the D programming language. If you don't know what D is, long story short: C++ with Garbage Collection (optionally removed @nogc) and no enforced backwards compatibility with C so it's a beautiful and quite powerful language. Facebook is investing heavily in D, worth a look. No need to obfuscate your already terrible C#, becomes compiled into native code.
Anyway back to 4chan.
~ Moogly
P.S. If you don't know what this is for, don't worry, I leave this here for those who love this kind of thing, and for future developers who may need it. Maybe next time as I browse through 4chan more code will pop up into my editor again.
usage:
Code:
void main()
{
base64Encoding b64 = new base64Encoding();
int x = 1;
string encodedX = b64.Encode(x); // Gives back "@A"
writefln("Converting %s from Base64> %d", y, decodedY);
}
PPS:
Screenshot of it working!
PPPS:
TUNNEL SNAKES RULE!
Attachments
You must be registered for see attachments list