Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Encryption using XOR

Posted on 1999-09-20
Medium Priority
511 Views
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
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'+OutPutString
Else
OutPutString:='0'+OutPutString;
End;
Inc(WorkByte);
End;
ConvertToBinary:=OutPutString;
End;
0
Question by:PsychoFox
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 1

Accepted Solution

columbo666 earned 1000 total points
ID: 2060209
you don't have to convert it. you just can go trough the string :

***********************************************************

uses crt;

var instr,outstr:string;i:integer;

procedure encode(cv:byte;instr:sting; var outstr:string);

begin
outstr:=instr;   {put the correct lenght of instr}
for i:=1 to length(instr) do {go trough the string}
mem[seg(outstr):ofs(outstr)+i]:=(mem[seg(instr):ofs(instr)+i]) xor cv;  {encode it}
end;

begin
instr:='this is a little test, and a very good text !'
writeln(instr);
encode(53,instr,outstr);  {encode with 53 as value}
writeln(outstr);
encode(53,outstr,instr);  {decode with 53 as value}
writeln(instr);  {here should appear the same text again}
end.

**********************************************************

if you've got any questions, mail me : columbo666@iname.com

hope, 'could help
columbo666
0

Author Comment

ID: 2060273
Thank you! The encoding works great.

I will accept your answer as soon as my program is ready (i may have some more questions :) ).
0

LVL 1

Expert Comment

ID: 2060285
cool. mail me
0

Author Comment

ID: 2060443
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?
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re involved with your company’s wide area network (WAN), you’ve probably heard about SD-WANs. They’re the “boy wonder” of networking, ostensibly allowing companies to replace expensive MPLS lines with low-cost Internet access. But, are they …
What we learned in Webroot's webinar on multi-vector protection.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
###### Suggested Courses
Course of the Month5 days, 20 hours left to enroll