DarkCryptTC - Total Commander now is the best encryptor!!!
Moderators: Hacker, petermad, Stefan2, white
- alexanderwdark
- Senior Member
- Posts: 270
- Joined: 2008-04-14, 07:20 UTC
- Location: Russia
- Contact:
- alexanderwdark
- Senior Member
- Posts: 270
- Joined: 2008-04-14, 07:20 UTC
- Location: Russia
- Contact:
XXTEA implementation how to use from wikipedia
Hi
I am trying to implement in C code XXTEA.
please help me with the code
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/* #define MX (z>>5^y<<2) + (y>>3^z<<4)^(sum^y) + (key[p&3^e]^z) */
#define MX ( (((z>>5)^(y<<2))+((y>>3)^(z<<4)))^((sum^y)+(key[(p&3)^e]^z)) )
long btea(long* v, long length, long* key);
void main()
{
long length;
unsigned char buffer[30];
unsigned char key[30];
strcpy(buffer,"9248979020");
strcpy(key,"7813498");
length = strlen((long *)buffer);
printf("original buffer %s %ld\n",buffer,length);
btea((long *)buffer,length,(long *)key);
length = strlen((long *)buffer);
printf("encrypted buffer %s %ld\n",(char *)buffer,length);
length = - length;
btea((long *)buffer,length,(long *)key);
length = strlen((long *)buffer);
printf("decrypted buffer %s %ld \n",(char *)buffer,length);
getchar();
getchar();
}
long btea(long* v, long length, long* key) {
unsigned long z /* = v[length-1] */, y=v[0], sum=0, e, DELTA=0x9e3779b9;
long p, q ;
if (length > 1) { /* Coding Part */
z=v[length-1]; /* Moved z=v[length-1] to here, else segmentation fault in decode when length < 0 */
q = 6 + 52/length;
while (q-- > 0) {
sum += DELTA;
e = (sum >> 2) & 3;
for (p=0; p<length-1; p++) y = v[p+1], z = v[p] += MX;
y = v[0];
z = v[length-1] += MX;
}
return 0 ;
} else if (length < -1) { /* Decoding Part */
length = -length;
q = 6 + 52/length;
sum = q*DELTA ;
while (sum != 0) {
e = (sum >> 2) & 3;
for (p=length-1; p>0; p--) z = v[p-1], y = v[p] -= MX;
z = v[length-1];
y = v[0] -= MX;
sum -= DELTA;
}
return 0;
}
return 1;
}
I am trying to implement in C code XXTEA.
please help me with the code
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/* #define MX (z>>5^y<<2) + (y>>3^z<<4)^(sum^y) + (key[p&3^e]^z) */
#define MX ( (((z>>5)^(y<<2))+((y>>3)^(z<<4)))^((sum^y)+(key[(p&3)^e]^z)) )
long btea(long* v, long length, long* key);
void main()
{
long length;
unsigned char buffer[30];
unsigned char key[30];
strcpy(buffer,"9248979020");
strcpy(key,"7813498");
length = strlen((long *)buffer);
printf("original buffer %s %ld\n",buffer,length);
btea((long *)buffer,length,(long *)key);
length = strlen((long *)buffer);
printf("encrypted buffer %s %ld\n",(char *)buffer,length);
length = - length;
btea((long *)buffer,length,(long *)key);
length = strlen((long *)buffer);
printf("decrypted buffer %s %ld \n",(char *)buffer,length);
getchar();
getchar();
}
long btea(long* v, long length, long* key) {
unsigned long z /* = v[length-1] */, y=v[0], sum=0, e, DELTA=0x9e3779b9;
long p, q ;
if (length > 1) { /* Coding Part */
z=v[length-1]; /* Moved z=v[length-1] to here, else segmentation fault in decode when length < 0 */
q = 6 + 52/length;
while (q-- > 0) {
sum += DELTA;
e = (sum >> 2) & 3;
for (p=0; p<length-1; p++) y = v[p+1], z = v[p] += MX;
y = v[0];
z = v[length-1] += MX;
}
return 0 ;
} else if (length < -1) { /* Decoding Part */
length = -length;
q = 6 + 52/length;
sum = q*DELTA ;
while (sum != 0) {
e = (sum >> 2) & 3;
for (p=length-1; p>0; p--) z = v[p-1], y = v[p] -= MX;
z = v[length-1];
y = v[0] -= MX;
sum -= DELTA;
}
return 0;
}
return 1;
}
- alexanderwdark
- Senior Member
- Posts: 270
- Joined: 2008-04-14, 07:20 UTC
- Location: Russia
- Contact:
Re: XXTEA implementation how to use from wikipedia
Use XTEA or RTEA code - they simple and has same security as xxtea.
See lot of ciphers source codes on my page here
This is one of XXTEA implementations, functions encrypts/derypts 30 unsigned long values block (optimal for XXTEA, more for xxtea_crypt is not so secure).
How to use it. You must implement also some hash function (i.e. Ripe-MD 128, XorBuff function and function to generate IV)
See lot of ciphers source codes on my page here
This is one of XXTEA implementations, functions encrypts/derypts 30 unsigned long values block (optimal for XXTEA, more for xxtea_crypt is not so secure).
Code: Select all
/**********************************************************
XXTEA 30 u32's - Tiny Encryption Algorithm
Unrolled, tweaked by A.Myasnikov, DarkSoftware
************************************************************/
#include <string.h>;
#define u32 unsigned long
u32 key[4];
#define MX ( (((z>>9)^(y<<2))+((y>>3)^(z<<6)))^((sum^y)+(key[(p&3)^e]^z)) )
void xxtea_crypt (u32* v) {
unsigned long z, y=v[0], sum=0, e, DELTA=0x9e3779b9;
long p, q=12;
z=v[29];
while (q-- > 0) {
sum += DELTA;
e = (sum >> 2) & 3;
for (p=0; p<29; p++) y = v[p+1], z = v[p] += MX;
y = v[0];
z = v[29] += MX;
}
}
void xxtea_decrypt (u32* v) {
unsigned long z, y=v[0], sum=0, e, DELTA=0x9e3779b9;
long p, q=12;
sum = q*DELTA ;
while (sum != 0) {
e = (sum >> 2) & 3;
for (p=29; p>0; p--) z = v[p-1], y = v[p] -= MX;
z = v[29];
y = v[0] -= MX;
sum -= DELTA;
}
}
void __export __stdcall setup (u32 *data)
{
memmove(&key[0],&data[0],16);
}
void __export __stdcall crypt (u32 *data)
{
xxtea_crypt(data);
}
void __export __stdcall decrypt (u32 *data)
{
xxtea_decrypt(data);
}
How to use it. You must implement also some hash function (i.e. Ripe-MD 128, XorBuff function and function to generate IV)
Code: Select all
procedure xxteatw30comp (si, st, key: string);
var
FileIn, FileOut: TFileStream;
Buffer, Dest: array [0..119] of byte;
iv: array [0..119] of byte;
iv2: array [0..15] of byte;
iv3: array [0..7] of byte;
xbuf: array [0..119] of byte;
BlockSize: longword;
Left, I, N: longint;
FName: string;
digest: array[0..15] of byte;
var
setup: procedure (key: pointer); stdcall;
var
crypt: procedure (froms: pointer); stdcall;
var
hdll: THandle;
begin
hdll := LoadLibrary(PChar(dll + 'libxxtea30.dll'));
if hdll <> 0 then
begin
setup := Windows.GetProcAddress(hdll, 'setup');
crypt := Windows.GetProcAddress(hdll, 'crypt');
if (@crypt = nil) or (@setup = nil) then
begin
ShowMessage('Functions not found!');
end;
end
else
ShowMessage('XXTEA-tw30 not loaded!');
// Here use get hash digest of key string
FillChar(iv3, 8, $FF);
FillChar(iv, 120, $FF);
// Here compute iv block
prg := 0;
FileIn := TFileStream.Create(si, fmOpenRead or fmShareDenyWrite);
FileOut := TFileStream.Create(st, fmCreate);
Left := FileIn.Size;
FillChar(Buffer, 120, 0);
FillChar(Dest, 120, 0);
setup(@digest);
repeat
if left < 120 then
begin
for n := 0 to 119 do
buffer[n] := random(256) xor rndtick;
end;
blocksize := 120;
FileIn.Read(Buffer, blocksize);
XorBuff(@Buffer, @Iv, 120, @XBuf); // Here write CBC routine
Crypt(@XBuf);
Move(XBuf, Iv, 120);
FileOut.Write(XBuf, blocksize);
ShowPDP(PChar(si), blocksize); // Some progress bar
Dec(left, blocksize);
until left <= 0;
FileIn.Destroy;
FileOut.Destroy;
if hdll <> 0 then
FreeLibrary(hdll);
end;
procedure xxteatw30dcomp (si, st, key: string);
var
FileIn, FileOut: TFileStream;
Buffer, Dest: array [0..119] of byte;
iv: array [0..119] of byte;
iv2: array [0..15] of byte;
iv3: array [0..7] of byte;
xbuf: array [0..119] of byte;
BlockSize: longword;
Left, I, N: longint;
FName: string;
digest: array[0..15] of byte;
var
setup: procedure (key: pointer); stdcall;
var
crypt: procedure (froms: pointer); stdcall;
var
hdll: THandle;
begin
hdll := LoadLibrary(PChar(dll + 'libxxtea30.dll'));
if hdll <> 0 then
begin
setup := Windows.GetProcAddress(hdll, 'setup');
crypt := Windows.GetProcAddress(hdll, 'decrypt');
if (@crypt = nil) or (@setup = nil) then
begin
ShowMessage('Functions not found!');
end;
end
else
ShowMessage('XXTEA-tw30 not loaded!');
// key ---> digest
FillChar(iv3, 8, $FF);
FillChar(iv, 120, $FF);
// ---> iv
prg := 0;
FileIn := TFileStream.Create(si, fmOpenRead or fmShareDenyWrite);
FileOut := TFileStream.Create(st, fmCreate);
Left := FileIn.Size;
FillChar(Buffer, 120, 0);
FillChar(Dest, 120, 0);
setup(@digest);
repeat
blocksize := 120;
FileIn.Read(Buffer, blocksize);
Move(buffer, Dest, 120);
Crypt(@Buffer);
XorBuff(@Buffer, @Iv, 120, @XBuf);
Move(Dest, Iv, 120);
FileOut.Write(XBuf, blocksize);
ShowPDP(PChar(si), blocksize); // process
Dec(left, blocksize);
until left <= 0;
FileIn.Destroy;
FileOut.Seek(arcrec.size, 0);
FileOut.Size := arcrec.size; // Because of size is x*120 bytes long setting correct length
FileOut.Destroy;
if hdll <> 0 then
FreeLibrary(hdll);
end;
- alexanderwdark
- Senior Member
- Posts: 270
- Joined: 2008-04-14, 07:20 UTC
- Location: Russia
- Contact:
Re: XXTEA implementation how to use from wikipedia
29.11.2008: Strong optimization, speedup of many cipher engines,
- fenix_productions
- Power Member
- Posts: 1979
- Joined: 2005-08-07, 13:23 UTC
- Location: Poland
- Contact:
2CG!
Here you go:
http://cid-e12762cbdafb3c47.skydrive.live.com/self.aspx/TC/darkcrypt%7C_GUI%7C_20080915.zip
Here you go:
http://cid-e12762cbdafb3c47.skydrive.live.com/self.aspx/TC/darkcrypt%7C_GUI%7C_20080915.zip
"When we created the poke, we thought it would be cool to have a feature without any specific purpose." Facebook...
#128099
#128099
- alexanderwdark
- Senior Member
- Posts: 270
- Joined: 2008-04-14, 07:20 UTC
- Location: Russia
- Contact:
Thanx, link to GUI fixed!
Link for the latest version of DarkCrypt GUI (29.11.2008)
Please, use this, latest version, it contains optimized version of darkcrypttc and all the latest cipher implementations.
Link for the latest version of DarkCrypt GUI (29.11.2008)
Please, use this, latest version, it contains optimized version of darkcrypttc and all the latest cipher implementations.
- alexanderwdark
- Senior Member
- Posts: 270
- Joined: 2008-04-14, 07:20 UTC
- Location: Russia
- Contact:
Yeah,it would be enough, GUI is unchanged, just recompiled and repacked by PE-packer in build script.CG! wrote:Thanks again.
The new link works ... even for me. ^^
Thought copying the new plugin into the somelibs folder would be enough, but the new GUi executable is 2b bigger.
P.S. There is new build of darkcrypt plugin with optimized stream reading engine for some ciphers, it was uploaded today on 11.20 GMT

DarkCryptTC II
DarkCrypt GUI
- alexanderwdark
- Senior Member
- Posts: 270
- Joined: 2008-04-14, 07:20 UTC
- Location: Russia
- Contact:
04.12.2008 DarkCrypt III, most secure key and IV generation and transforming (special Skein hash function rounds), version can't handle DarkCrypt II files, please decrypt before update (!)
DarkCryptTC II
DarkCrypt GUI
DarkCryptTC II
DarkCrypt GUI
- alexanderwdark
- Senior Member
- Posts: 270
- Joined: 2008-04-14, 07:20 UTC
- Location: Russia
- Contact:
06.12.2008 1:15 GMT Re-uploaded fixed DarkCrypt III (some other ciphers now has special strong iv-generator and keysetup, please, decipher all files)
DarkCryptTC II
DarkCrypt GUI
DarkCryptTC II
DarkCrypt GUI
- alexanderwdark
- Senior Member
- Posts: 270
- Joined: 2008-04-14, 07:20 UTC
- Location: Russia
- Contact:
06.12.2008 19:00 GMT New! Use integrated Crypto-safe password generator (right-click on the cd button in main window)
DarkCryptTC II
DarkCrypt GUI
DarkCryptTC II
DarkCrypt GUI