home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Unsorted BBS Collection
/
thegreatunsorted.tar
/
thegreatunsorted
/
programming
/
misc_programming
/
batnmore.z!p
/
CAESAR.BTM
< prev
next >
Wrap
Text File
|
1992-11-15
|
3KB
|
92 lines
*REM This batch file is Freeware, free to use and redistribute unmodified *
*REM Jouni Miettunen * jon@stekt.oulu.fi * Oulu * Finland * Europe * 1992 *
REM Caesar Cipher encryption, default rot13. Look at the end of this file!
REM Timestamp 15-Nov-1992
break on^setlocal^unalias *^if %#==0 goto info^set rot=13
REM Is there rotation key or do we use default 13
iff %@ascii[%1]==45 then
if %#==1 goto start
iff not exist %1 then^set rot=%@eval[%@substr[%1,1,%@len[%1]]%%26]^shift^endiff
endiff
:start
iff exist %1 then^gosub work^else^set a=%1^gosub loop^endiff
shift^if "%1" != "" goto start^goto end
:work
iff "%@search[pre4rot.exe]"=="" then^echo ----- Cannot find PRE4ROT.EXE^return
set b=%@unique[%temp]^type %1|pre4rot>%b^for %a in (@%b) gosub loop^del/q %b^return
:loop
set index=%@eval[%index+1]
REM %a has to be in quotation marks in case it includes commas
REM space has to follow %a in case %a is only CR/LF or NL
REM Problem now: double and single quotes, procents in %a (C code at EOF)
set x=%@ascii[%@substr["%a ",%index,1]]
iff %x ge 65 .and. %x le 90 then
set x=%@eval[%x+%rot]^if %x gt 90 set x=%@eval[%x-26]
elseiff %x ge 97 .and. %x le 122 then
set x=%@eval[%x+%rot]^if %x gt 122 set x=%@eval[%x-26]
endiff
iff %x==32 then^echos ` `
elseiff %x==60 then^echos `<`
elseiff %x==62 then^echos `>`
elseiff %x==94 then^echos `^`
elseiff %x==124 then^echos `|`
elseiff %x==0 then^echos %@substr["%a ",%index,2]^set index=%@eval[%index+1]
else^echos %@char[%x]^endiff
if %index lt %@len[%a] goto loop^set index=0^echo.^return
:info
echo Usage: %@lower[%@name[%0]] [-key] [string | filename ...]
text
One of the simplest and oldest encryption methods: Caesar Cipher
-key integer (1..26) for key rotation
Default key is 13, when Caesar Cipher is also known as rot13
Input can be a string on command line or in a file. If input has single
quotes, double quotes or procent characters, it *has* to be in file.
For files uses pre4rot.exe filter (c code included) to place 4DOS escape
character (by default ctrl-x) in front of single quote, double quote and
procent characters. Creates temperature file in TEMP directory.
endtext
:end
break off^quit
REM Damn it! (Damnant quod non intelligunt)
REM I can change _output_ of _pressed_ char, can do nothing to _input_
REM Have to add some C code :-( And if u need some, then u could have the
REM whole thing written in C.. Well, it almost worked w/only 4DOS commands!
: /* pre4rot.c - add 4DOS escape character in front of single quotes, */
: /* double quotes and procent characters - ANSI C code */
:
: #include <stdio.h>
:
: void main(void)
: {
: int c;
:
: while ((c=getchar()) != EOF) {
: if ((c==34) || (c==37) || (c==96)) putchar(24);
: putchar(c);
: } /*while*/
: } /*void main*/
REM problem: what if escape character is something else than ctrl-x?
REM ...I had to use c, so it really doesn't matter any more... :-(
REM Note: getenv() doesn't find COMPOUND. Has to use 4DOS commands..