PsychoFox
asked on
Encryption using XOR
I'm doing at school project about simple cryptography.
My assignement is too write a simple program that takes an input (string), converts it to binary form and then uses a 8 bit key to encrypt the message (using the XOR function).
The answer should be shown both in binary form (1 and 0's and in ascii).
Could anyone write an example, i'm kinda in hurry...
This is the function i use to convert to binary :
Function ConvertToBinary(TheInt: Integer): String;
Const
BitMask: Byte = $01;
Var
SizeOfVar,Bytes,I: Byte;
WorkByte: ^Byte;
OutPutString: String;
Begin
OutPutString:='';
WorkByte:=Ptr(Seg(TheInt), Ofs(TheInt ));
For Bytes:=1 to 2 do
Begin
For I:=0 to 7 do
Begin
If (WorkByte^ And BitMask) > 0 Then
OutPutString:='1'+OutPutSt ring
Else
OutPutString:='0'+OutPutSt ring;
BitMask:=BitMask Shl 1;
End;
Inc(WorkByte);
BitMask:=$01
End;
ConvertToBinary:=OutPutStr ing;
End;
My assignement is too write a simple program that takes an input (string), converts it to binary form and then uses a 8 bit key to encrypt the message (using the XOR function).
The answer should be shown both in binary form (1 and 0's and in ascii).
Could anyone write an example, i'm kinda in hurry...
This is the function i use to convert to binary :
Function ConvertToBinary(TheInt: Integer): String;
Const
BitMask: Byte = $01;
Var
SizeOfVar,Bytes,I: Byte;
WorkByte: ^Byte;
OutPutString: String;
Begin
OutPutString:='';
WorkByte:=Ptr(Seg(TheInt),
For Bytes:=1 to 2 do
Begin
For I:=0 to 7 do
Begin
If (WorkByte^ And BitMask) > 0 Then
OutPutString:='1'+OutPutSt
Else
OutPutString:='0'+OutPutSt
BitMask:=BitMask Shl 1;
End;
Inc(WorkByte);
BitMask:=$01
End;
ConvertToBinary:=OutPutStr
End;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
cool. mail me
ASKER
Explanation :
1011 This is the first key
abcd Just to make i more clear
1 XOR 1 = 0
a a
1 XOR 0 = 1
a b
1 XOR 1 = 0
a c
1 XOR 1 = 0
a d
From the first bit we got this new key 0100
We go on to the next bit
0 XOR 1 = 1
b a
0 XOR 0 = 0
b b
0 XOR 1 = 1
b c
0 XOR 1 = 1
b d
This will become 1011
And so on with all the four bits until we have a
16bit key.
Could you help me writing a procedure that does that?
1011 This is the first key
abcd Just to make i more clear
1 XOR 1 = 0
a a
1 XOR 0 = 1
a b
1 XOR 1 = 0
a c
1 XOR 1 = 0
a d
From the first bit we got this new key 0100
We go on to the next bit
0 XOR 1 = 1
b a
0 XOR 0 = 0
b b
0 XOR 1 = 1
b c
0 XOR 1 = 1
b d
This will become 1011
And so on with all the four bits until we have a
16bit key.
Could you help me writing a procedure that does that?
ASKER
I will accept your answer as soon as my program is ready (i may have some more questions :) ).