Clever. I would suggest creating a local for newtext as IntStack instead of String to reduce GC thrash on Android, since strings are immutable, or an int array of the input length, then generating the string at the very end from the chars.
Here's an old piece of code from my vault:
Function Main:Int()
Print ChimpCipher("You are now totally encoded, good work.", "Longer keys are better")
Print ChimpCipher(ChimpCipher("You are now totally encoded, good work.", "Longer keys are better"), "Longer keys are better")
End Function
'Summary: Encrypts a string using a XOR table.
Function ChimpCipher:String(input:String, key:String)
Local out:int[input.Length] 'output string chars
Local k:Int 'Key iterator
For Local i:Int = 0 Until input.Length
Local ochr:Int = input[i]
If k >= key.Length Then k = 0 'cycle
out[i] = ochr ~ key[k]
k += 1
Next
Return String.FromChars(out)
End Function
|