View Single Post
  #1  
Old 05-27-2013, 08:42 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
An encrypt/decrypt function

Hi, haven't been active on the forums in a while but I was looking for some feedback, the last time I attempted a cipher, it didn't use a key and was pretty basic. Here is my latest attempt, what do you guys/gals think?

Uses:
To encrypt sensitive player attributes.
To encrypt any string on the server really.

Pros:
Makes strings semi-secure.

Cons:
Makes strings long.

PHP Code:
/*
  The logic of this encryption is basically
  Get a key/salt and get a numerical value
  from the string, so to get that we convert it
  to numbers by getting each ascii value of
  each character, this gives us an integer
  that we can use as a salt.
  
  Once we have out key, we then get each character
  of the string to encrypt, get the ascii of it
  which returns an integer, plus that with the salt
  and add it to an array sort of thing with a seperator
  chacarter.
  
  We also base64 it both ways to make it look more neat.
*/
//Seperator character.
const sep ".";
function 
Encrypt(stringkey){
  
temp.key RealKey(key);
  
temp.str;
  for(
temp.0string.length(); ++){
    
temp.letter string.substring(i, +1);
    
temp.letter getascii(temp.letter);
    
temp.str temp.str@temp.letter+key@sep;
  }
  return 
base64encode(temp.str);
}
function 
Decrypt(stringkey){
  
temp.string base64decode(string);
  
temp.key RealKey(key);
  
temp.str;
  
temp.tok string.tokenize(sep);
  for(
temp.0tok.size(); ++){
    
temp.letter tok[i];
    
temp.letter char(temp.letter-key);
    
temp.str temp.str@letter;
  }
  return 
temp.str;
}
function 
RealKey(key){
  
temp.char;
  for(
temp.0key.length(); ++){
    
temp.letter key.substring(i, +1);
    
temp.code getascii(temp.letter);
    
temp.char += temp.code;
  }
  return 
int(temp.char/2);

__________________

Gund for president.

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

Last edited by Gunderak; 05-27-2013 at 09:28 AM..
Reply With Quote