Sign in to follow this  
Followers 0
LordBlackout

One Time Pad Algorhitym

12 posts in this topic

Hi all! :unsure:

I have a problem: I want to implement the One Time Pad Algorhitym in AutoIt, by XORing file's bits with key's bits. The problem is that I have no idea about reading single bits from a file.. any help?

Thanks!

Share this post


Link to post
Share on other sites



Lookup help for fileopen in binary mode. Read chunks of bytes, perform your xor and write.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi, I tried FileOpen in binary mode, but the representation is not binary.. it contains 0-9 digits and some letters, I think is HEX..

Edited by LordBlackout

Share this post


Link to post
Share on other sites

Yes, I know, but how can I make the XOR with HEX? Is there a way to obtain single bits?

Share this post


Link to post
Share on other sites

Open input in binary mode

open output in binary mode

read a byte

if eof exitloop

xor with corresponding byte in pad

write result

loop

Hexadecimal is simply a "human-friendly" representation of data. You can display data in hex, octal, ASCII, UTF, whatever suits the need for you to comprehend it. Displaying data under one form or another doesn't change it but some forms give you a better understanding/readability. E.g. displaying text in hex isn't particularly easy to read.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Thanks for the reply, but I don't understand a thing:

Hex contains letters, that are not XORable..

Share this post


Link to post
Share on other sites

You really should google about things you don't understand.

Look: say you have a file wich contents the string AB3. Ok this is one representation, suited to human eyes and brain.

This ASCII string translates into hex as 41 42 33. This is a second representation, somehow less readable but your brain can still get it if you look at an ASCII table.

In octal, you obtain 101 102 063. This is a fourth representation of the same string. Somehow unusual and much less readable.

In binary, this is 01000001 01000010 00110011. This is a fourth representation of the very same data. Even if you can "read" the series of 0 and 1, it's now much harder to understand that these bits mean AB3.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Thanks for the explanation, but is non this the thing that I don't understand.. I am googling but I can't find a solution:

If I take a byte from a Hex string, let's say "A", how can I XOR this byte? (BitXOR doesn't XOR letters)..

I could transform it in ASCII, but the variable number of digits is a problem when decoding..

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

This ASCII string translates into hex as 41 42 33

so work with that

$string = "AB3"
$Sarray = stringsplit($string , "" , 2)

for $i = 0 to ubound($Sarray) - 1
    $bin = stringtrimleft(binary($Sarray[$i]) , 2)
$Sarray[$i] = $bin
Next

$xor = BitXOR($Sarray[0] , $Sarray[1] , $Sarray[2])

msgbox (0, '' , $Xor)
Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Thanks, following your example I tried this:

$ID = FileOpen($File, 16)
                $File = StringSplit(StringToBinary(StringTrimLeft(FileRead($ID), 2)), "")
                FileClose($ID)
                $ID = FileOpen($Chiave, 16)
                $Chiave = StringSplit(StringToBinary(StringTrimLeft(FileRead($ID), 2)), "")
                FileClose($ID)
                If $Chiave[0] < $File[0] Then
                    MsgBox(16, "Errore", "La chiave è troppo corta.")
                Else
                    For $a = 3 To $File[0] Step 1
                        $File[$a] = BitXOR($File[$a], $Chiave[$a])
                    Next
                    $File = "0x" & BinaryToString(_ArrayToString($File, "", 1))
                    $ID = FileOpen($NewFile, 18)
                    FileWrite($ID, $File)
                    MsgBox(64, "Info", "Operazione completata con successo.")
                EndIf

But doesn't work.. the file isn't decrypted and becomes unreadable.

Edited by LordBlackout

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0