Article View: comp.lang.pascal.misc
Article #150Re: *******REVERSE ASCII**********
From: CLIF PENN
Date: Sun, 29 Sep 1996 00:00
Date: Sun, 29 Sep 1996 00:00
97 lines
3381 bytes
3381 bytes
johnyreb@ix.netcom.com(Richard Elbert Davis) wrote:
>Hey,
>I know of a college who reversed ASCII values for an encryption
>program. DOES ANYONE KNOW THE CODE TO DO THIS.
>-Jarrod
Jarrod,
"REVERSE ASCII" can be interpreted in several ways:--
(1) Using 'z' for 'a', and vice versa, etc.
(2) Taking the ASCII value, two decimal digits, and reversing the
digits.
(3) Taking the binary byte representing the char and putting 0's
in place of 1's and vice versa.
(4) Working from ASCII 255 to 0 and interchanging these values.
None of these is secure, may have buried control chars and all are
easily "cracked".
However, all of these use a char by char substitution. If that is
really what you want, you can do this with a CASE statement, linked
list, Arrays or Strings. In the following simple, non-secure scheme,
a string key is used as an example. Making it into 5 letter code
groups makes it no more secure, so I did not bother.
Regards,
Clif <clifpenn@airmail.net> }
Program SubstituteEncryption;
CONST
test1 = 'the quick brown fox jumped over the lazy dogs back';
test2 = 'FROM HERE TO ETERNITY IS A VERY LONG TIME';
VAR
Original, CodeKey, source, coded, msg:String;
Ch:Char;
Procedure StripSpaces(VAR s:String);
VAR p:Byte ;
Begin
Repeat
p := POS(' ', s);
If p > 0 then Delete(s, p, 1);
Until p = 0;
End;
Procedure Encode(VAR c:String);
VAR i, j:Byte;
Begin
For i := 1 to Length(c) Do
Begin
j := POS(c[i], Original);
c[i] := CodeKey[j];
End;
End;
Procedure Decode(VAR m:String);
VAR x, y:Byte;
Begin
For x := 1 to Length(m) Do
Begin
y := POS(m[x], CodeKey);
m[x] := Original[y];
End;
End;
Begin
Writeln; Writeln; Writeln;
Original := '';
For Ch := 'A' to 'Z' Do Original := Original + Ch;
For Ch := 'a' to 'z' Do Original := Original + Ch;
Writeln('Original: '); Writeln(Original);
CodeKey := ''; (* reverse of Original *)
For Ch := 'A' to 'Z' Do CodeKey := Ch + CodeKey ;
For Ch := 'a' to 'z' Do CodeKey := Ch + CodeKey ;
Writeln('CodeKey: '); Writeln(CodeKey);
source := test1 + test2;
StripSpaces(source);
Writeln('Source without spaces: '); Writeln(source);
coded := source;
Encode(coded);
Writeln('Coded: '); Writeln(coded);
msg := coded;
Decode(msg);
Writeln('Decoded: '); Writeln(msg);
Writeln(source); Writeln('Above is source without spaces.');
Writeln; Write('<<< Press Enter>>>':20); Readln;
End.
Technical Details
Message-ID:
<52k9sj$6p2@library.airnews.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<1996Sep27.160013.6675@arl.mil> <52jbao$c98@dfw-ixnews4.ix.netcom.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10261c,38608a28b5863775 X-Google-Attributes: gid10261c,public X-Google-Thread: 111659,8746d3f6e7cf3444 X-Google-Attributes: gid111659,public X-Google-Thread: 102601,8746d3f6e7cf3444 X-Google-Attributes: gid102601,public X-Google-Thread: 11185f,8746d3f6e7cf3444 X-Google-Attributes: gid11185f,public From: clifpenn@airmail.net (CLIF PENN) Subject: Re: *******REVERSE ASCII********** Date: 1996/09/29 Message-ID: <52k9sj$6p2@library.airnews.net> X-Deja-AN: 185898398 references: <1996Sep27.160013.6675@arl.mil> <52jbao$c98@dfw-ixnews4.ix.netcom.com> organization: INTERNET AMERICA newsgroups: comp.lang.pascal.misc,comp.lang.pascal.borland,ctdl.lang.pascal,osu.pascal