
#NoEnv ;#include FileHelper.ahk MCode(ByRef code, hex) { ; allocate memory and write Machine Code there VarSetCapacity(code,StrLen(hex)//2) Loop % StrLen(hex)//2 NumPut("0x" . SubStr(hex,2*A_Index-1,2), code, A_Index-1, "Char") } MCode(enc, "5589E557565383EC24C745F000000000C745ECB979379E8B4510C1E8038945D8C745E8000000008B45E83B45D80F831F0100" . "00C745F000000000C745E4000000008B45E43B45140F83FB0000008B45E88D34C5000000008B7D088B45E8C1E0038945D48B45088945D" . "08B45E8C1E00303450883C0048B0089C2C1E2048B45E8C1E00303450883C0048B00C1E80531C28B45E8C1E00303450883C00489D30318" . "8B45F083E0038D0C85000000008B550C8B45F003041131D88B55D48B4DD003040A89043E8B55EC8D45F001108B45E8C1E0030345088D7" . "0048B45E8C1E0030345088D78048B45E88D14C5000000008B45088B040289C1C1E1048B45E88D14C5000000008B45088B0402C1E80531" . "C18B45E88D14C5000000008B450889CB031C028B45F0C1E80B83E0038D0C85000000008B550C8B45F003041131D8030789068D45E4FF0" . "0E9F9FEFFFF8D45E8FF00E9D5FEFFFF83C4245B5E5F5DC3") MCode(dec, "5589E557565383EC24C745F000000000C745ECB979379E8B4510C1E8038945D8C745E8000000008B45E83B45D80F832A0100" . "008B45EC0FAF45148945F0C745E4000000008B45E43B45140F83030100008B45E8C1E0030345088D70048B45E8C1E0030345088D78048" . "B45E88D14C5000000008B45088B040289C1C1E1048B45E88D14C5000000008B45088B0402C1E80531C18B45E88D14C5000000008B4508" . "89CB031C028B45F0C1E80B83E0038D0C85000000008B550C8B45F003041189DA31C28B0729D089068B55EC8D45F029108B45E88D34C50" . "00000008B7D088B45E8C1E0038945D48B45088945D08B45E8C1E00303450883C0048B0089C2C1E2048B45E8C1E00303450883C0048B00" . "C1E80531C28B45E8C1E00303450883C00489D303188B45F083E0038D0C85000000008B550C8B45F003041189DA31C28B4DD48B5DD08B0" . "41929D089043E8D45E4FF00E9F1FEFFFF8D45E8FF00E9CAFEFFFF83C4245B5E5F5DC3") MCode(k, 11111111222222223333333344444444) ; 128 bit key u = ( Join The simplest of the encryption modes is the electronic codebook (ECB) mode. The message is divided into block s and each block is encrypted separately. The disadvantage of this method is that identical plaintext blocks a re encrypted into identical ciphertext blocks; thus, it does not hide data patterns well. In some senses, it d oesn't provide serious message confidentiality, and it is not recommended for use in cryptographic protocols at all. The simplest of the encryption modes is the electronic codebook (ECB) mode. The message is divided into block s and each block is encrypted separately. The disadvantage of this method is that identical plaintext blocks a re encrypted into identical ciphertext blocks; thus, it does not hide data patterns well. In some senses, it d oesn't provide serious message confidentiality, and it is not recommended for use in cryptographic protocols at all. The simplest of the encryption modes is the electronic codebook (ECB) mode. The message is divided into block s and each block is en... ) Loop, 1024 v .= u len := StrLen(v) MsgBox, Encrypting 1 MB now... StartTime := A_TickCount DllCall(&enc, "uint",&v, "uint",&k, "uint",len , "uint",64) ElapsedTime := A_TickCount - StartTime MsgBox, %ElapsedTime% milliseconds have elapsed. MsgBox % v ;ReadMemory("output.enc", &v, len) ;v = empty ;WriteMemory("output.enc", v) MsgBox, Decrypting 1 MB now... StartTime := A_TickCount DllCall(&dec, "uint",&v, "uint",&k, "uint",len , "uint",64) ElapsedTime := A_TickCount - StartTime MsgBox, %ElapsedTime% milliseconds have elapsed. MsgBox % v
Could the C code be optimised?
EEXPORT void XTEA_encipher_ECB(unsigned long* v, unsigned long* k, unsigned long len, unsigned long rounds) { unsigned long sum=0, delta=0x9E3779B9, i, j; unsigned long v0, v1; unsigned long blocks = len/8; for(i=0; i<blocks; i++) { sum=0; for(j=0; j<rounds; j++) { v[i*2] += (((v[i*2+1] << 4) ^ (v[i*2+1] >> 5)) + v[i*2+1]) ^ (sum + k[sum & 3]); sum += delta; v[i*2+1] += (((v[i*2] << 4) ^ (v[i*2] >> 5)) + v[i*2]) ^ (sum + k[(sum>>11) & 3]); } } } EXPORT void XTEA_decipher_ECB(unsigned long* v, unsigned long* k, unsigned long len, unsigned long rounds) { unsigned long sum=0, delta=0x9E3779B9, i, j; unsigned long v0, v1; unsigned long blocks = len/8; for(i=0; i<blocks; i++) { sum=delta*rounds; for(j=0; j<rounds; j++) { v[i*2+1] -= (((v[i*2] << 4) ^ (v[i*2] >> 5)) + v[i*2]) ^ (sum + k[(sum>>11) & 3]); sum -= delta; v[i*2] -= (((v[i*2+1] << 4) ^ (v[i*2+1] >> 5)) + v[i*2+1]) ^ (sum + k[sum & 3]); } } }
Edit 20070922: Added comments showing how to Disk I/O.