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
4
Medium Priority
?
511 Views
Last Modified: 2012-06-21
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'+OutPutString
      Else
      OutPutString:='0'+OutPutString;
      BitMask:=BitMask Shl 1;
    End;
    Inc(WorkByte);
    BitMask:=$01
    End;
    ConvertToBinary:=OutPutString;
End;
0
Comment
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
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
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

by:PsychoFox
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

by:columbo666
ID: 2060285
cool. mail me
0
 

Author Comment

by:PsychoFox
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question