Got a bit bored and decided to code my own little encryption thing.
It basically get's a string and converts it into an ASCII array, it then multiplies each item in the array by a "key" and encodes that with base64.
The result ends up being relatively long but still pretty secure.
I don't intend for this to be used for passwords so i'm releasing it.
If you'd like to see what it does, iv'e attaches a screenshot.
Here's the class, name it "Encryption":
PHP Code:
//#CLIENTSIDE
function Encrypt(str){
temp.result = "";
//Loops through the individual characters.
for(i = 0; i < str.length(); i ++){
//Get's the character it's up to.
temp.char = str.substring(i, +1);
temp.num = getascii(char); //Converts it to ascii
//Adds the ASCII character to the array and also "hashes" it.
result.add(num/2*50/5);
}
//Encodes the already confusing string with base64.
//Typically used for encoding images but meh.
result = base64encode(result);
return temp.result;
}
function Decrypt(str){
temp.result = "";
//Decodes the string and turns it into a "hashed" ASCII array.
temp.str = base64decode(str);
//Splits the string into an array.
temp.tok = str.tokenize();
for(i = 0; i < tok.size(); i ++){
temp.char = tok[i]*2/50*5;
//Returns the character from ASCII form.
result = result@char(char);
}
return temp.result;
}
And here's an example of a use for it.
PHP Code:
//#CLIENTSIDE
function onCreated(){
this.join("Encryption");
}
function onWeaponFired(){
DrawGUI();
}
function DrawGUI(){
new GuiWindowCtrl("Encryption_Window") {
profile = GuiBlueWindowProfile;
clientrelative = true;
width = 331;
height = 286;
canmove = true;
canresize = false;
closequery = false;
destroyonhide = true;
canmaximize = false;
canminimize = false;
text = "Encryption";
x = screenwidth/2 - width/2;
y = screenheight/2 - height/2;
new GuiScrollCtrl("Text1_Scroll") {
profile = GuiBlueScrollProfile;
height = 114;
hscrollbar = "dynamic";
vscrollbar = "dynamic";
width = 320;
x = -1;
new GuiMLTextEditCtrl("Text1") {
profile = GuiBlueMLTextEditProfile;
height = 17;
horizsizing = "width";
text = "Hello World!";
width = 295;
}
}
new GuiScrollCtrl("Text2_Scroll") {
profile = GuiBlueScrollProfile;
height = 114;
hscrollbar = "dynamic";
vscrollbar = "dynamic";
width = 320;
y = 114;
x = -1;
new GuiMLTextCtrl("Text2") {
profile = GuiBlueMLTextProfile;
height = 17;
horizsizing = "width";
width = 295;
}
}
new GuiButtonCtrl("Encrypt") {
profile = GuiBlueButtonProfile;
text = "Encrypt";
width = 80;
y = 227;
x = -1;
}
new GuiButtonCtrl("Decrypt") {
profile = GuiBlueButtonProfile;
text = "Decrypt";
width = 80;
x = 240;
y = 227;
}
}
}
function Encrypt.onAction() {
Text2.text = Encrypt(Text1.text);
}
function Decrypt.onAction() {
Text2.text = Decrypt(Text1.text);
}
This isn't the most efficient way of encrypting strings, but I just wanted to attempt it.
I originally wanted to return the binary of the strings but graal doesn't contain a default way to do it.
Meaning i'd have to write a really long code and try to comprehend confusing formulas.