Cracking XOR Encryption

Source code example of how to break encryption using Delphi's random() function and XOR.

[Cracking XOR Encryption]

drop a button and edit box on the form, text in the edit box has to be at least 8 chars. if you're using to actualy break an encrypted string, just fill buffer [0..7] with encrypted data and fill [0..7] with the plaintext you assume is encrypted (pretty easy, you username of something of the sort).

I'd like to thank Cheng Wei (on for pointing out my rediculously slow calls to Edit1.text[i]. I've rethought the algorithm out, and it now tests keys as 2 longwords. as a result of this fix, it now scans 100,000,000 keys in 15seconds on my duron 600! WAAAHOOOOO! Thanks allot


procedure TForm1.Button1Click(Sender: TObject);

var i,j:longword;


    buffer:array[0..7]of byte;

    b:array[0..1]of longword absolute buffer[0];

    plaintext:array[0..7]of byte;

    p:array[0..1]of longword absolute plaintext[0];

    key:array[0..7]of byte;

    k:array[0..1]of longword absolute key[0];




   if length(edit1.text)<8 then exit;

   for i:=0 to 7 do



      buffer[i]:=plaintext[i] xor random(256);//encrypt




      for j:=0 to 1000000 do //loop is unrolled by compiler











         if b[0] xor k[0]=p[0] then //test key in blocks of 4

         if b[1] xor k[1]=p[1] then



            caption:='The key is: '+inttostr(i)+' ('+

               inttostr((thistime-lasttime)div 1000)+'sec)';







   until i>longword(MaxInt);



Share this article!

Follow us!

Find more helpful articles: