Thread: XOR Encryption
View Single Post
  #1  
Old 08-17-2008, 12:24 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
XOR Encryption

I'm not sure if anyone has done this before, but I was rather bored so I made a XOR Encryption function with my own additions to get rid of the parts of the ASCII character set that aren't really shown in Graal.

PHP Code:
/*Paramters:
s - string to be encrypted
usechars - boolean determining whether or not it changes ascii values into characters.
key - Encryption key. (Optional)  If left NULL it replaces with the default. s must be shorter or the same length as the encryption key.
*/
public function XOREncrypt(s, usechars, key) {
  if (
key == NULL)
    
key = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
temp.replace = "-";
  if (
s.length() <= key.length()) {
    
temp.out = "";
    for (
i=0; i<s.length(); i++) {
      
temp.a = getascii(s.charat(i)) xor getascii(key.charat(i));
      if (
usechars) {
        if (
temp.a > 32 && temp.a != 127) {
          
temp.a = char(temp.a);
          if (
temp.a = " ")
            
temp.a = temp.replace;
        }
        else 
temp.a = temp.replace;
      }
      
temp.out @= temp.a;
    }
    return 
temp.out;
  }
  else
    return 
"String too long. (Limit " @ key.length() @ ")";    
} 
Example:
PHP Code:
XOREncrypt("A nice cat", true, NULL); 
Which will return "-b--&#g+(>"

From what I hear, this method is hard, if not impossible to decrypt, and it's rather simple.
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote