
Using Result := Source will not work with ansi or wide strings either, because you want Result to be a unique copy of Source (because the Result copy gets modified). This is the primary reason why this routine will not work with ansi or wide strings. Move(Source, Result, Length(Source) + 1) is not the correct way to copy a string. Lifepower's latest version makes a few assumptions about the strings which is why it does not work with ansi or wide strings.
XTEA BLOCK CIPHER CODE CODE
I'm not sure why you didn't use that code in the first place. L := (Length(Input) + 7) and (not 7) Įdit: Incidentally, the Pascal code linked from that Wiki page does the same thing (in a different way). This is easily achieved with the following What you should do is set the length of Result to be the next highest multiple of eight over the length of Input. In your Encrypt and Decrypt methods, you are setting Result to the length of the input string, but inside the loop you overflow the buffer allocated for Result in the last call to Move by up to seven bytes (your last Move is always the size of TBlock64). While i b a brief look over both your code and Lifepower's, I have these comments. Raise Exception.Create('Error: You must define a password.') Procedure DecipherXTea(v: PBlock64 Key: PKey128) ĭec(v, ((v shl 4 xor v shr 5) + v) xor (Sum + Key)) ĭec(v, ((v shl 4 xor v shr 5) + v) xor (Sum + Key)) If Length(Key) b TXTea.Decrypt(const Input: string): string Procedure TXTea.InitKey(const Key: string) Procedure InitKey(const Key: string) įunction Encrypt(const Input: string): string įunction Decrypt(const Input: string): string Property Initialized: boolean read FInitialized default false (* please let us know and post your changes here: *) (* My only stipulation to this is that if you use it, adapt it or change it, *) (* Yuriy, he did the majority of the work in the end. (* and maybe mention us in the credits of whatever uses this.

Please leave this header in any subsequent distribution *) (* Translated from C into Object Pascal by Robert Kosek with much help from *) To use it just make a TXTea object, create it, Init the key, Encrypt/Decrypt then burn it. I'll be trying to juggle the discussion here and at Afterwarp, so just know that unless you check the thread there (), you might not be up to date on the problem. :oops: I have to thank Lifepower a lot just for helping me this far along! Any further help from ya'll will really be appreciated. It might work with a 16 character password, and a short paragraph, but change either around and it'll go screwy in no time flat!Īs you can guess it's got me fairly confused.
XTEA BLOCK CIPHER CODE PASSWORD
It seems to be something in relation to password length and content length. Like it could simply crash silently on me, or the encryption "halts" part way through. But my implementation is going wrong somewhere in the encryption and possibly decryption phases. XTea is supposed to be a simple encryption algorithm, and it is mathematically.

For a simple overview and pseudocode on XTea, you can wiki-it ().
