View Single Post
  #1  
Old 12-19-2012, 02:46 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Encryption of strings

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(0str.length(); ++){
    
//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(
0tok.size(); ++){
    
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";
    
screenwidth/width/2;
    
screenheight/height/2;

    new 
GuiScrollCtrl("Text1_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 114;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 320;
      
= -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;
      
114;
      
= -1;

      new 
GuiMLTextCtrl("Text2") {
        
profile GuiBlueMLTextProfile;
        
height 17;
        
horizsizing "width";
        
width 295;
      }
    }
    new 
GuiButtonCtrl("Encrypt") {
      
profile GuiBlueButtonProfile;
      
text "Encrypt";
      
width 80;
      
227;
      
= -1;
    }
    new 
GuiButtonCtrl("Decrypt") {
      
profile GuiBlueButtonProfile;
      
text "Decrypt";
      
width 80;
      
240;
      
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.
Attached Thumbnails
Click image for larger version

Name:	screenshot.png
Views:	154
Size:	36.2 KB
ID:	55242  
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote