My last attempts weren't very secure, so I thought of a new method.
Personally I think this is semi-secure, or at least harder to crack than my
last method.
The only flaw of it, the key must be at least 10 in length and can't have any repeated characters.
From what I can tell, this method is called "hashing".
PHP Code:
//#GS3
function onCreated():void{
var str:string = "abcdefghijklmnopqrstuvwxyz";
var cat:string = this.Enc(str, "!:#$%^&*()");
echo("Encrypted: "@cat);
var dog:string = this.Dec(cat, "!:#$%^&*()");
echo("Decrypted: "@dog);
}
function Enc(txt:string, key:string):string{
var str:string = "";
var i:number;
var j:number;
for(i = 0; i < txt.length(); i ++){
var letter:string = txt.charat(i);
var char:string = getascii(letter);
char = (char.length()>2?char:0@char);
var enc:string = "";
for(j = 0; j < 3; j ++){
var l:string = char.charat(j);
var e:string = key.charat(l);
enc @= e;
}
str @= enc;
}
return (str);
}
function Dec(txt:string, key:string):string{
var txt:string = (txt);
var str:string = "";
var i:number;
var j:number;
for(i = 0; i < txt.length(); i += 3){
var group:string = txt.substring(i, +3);
var dec:string = "";
for(j = 0; j < 3; j ++){
var letter:string = group.charat(j);
var num:number = key.pos(letter);
dec @= num;
}
str @= char(dec);
}
return str;
}
Encrypting the alphabet using this method produces the string:
!)*!)(!)):!!:!::!#:!$:!%:!^:!&:!*:!(:!)::!:::::#:: $::%::^::&::*::(::):#!:#::##
The last method, you could crack by trying 30 or so possible combinations, where as this one would require you to try a mass amount of combinations that you wouldn't want to have to go through and try and find the one that looks like something useful.
Also I think due to the maxlooplimit, the maximum length of the string would be 3,333.