Skip to content

Commit cd25885

Browse files
Add files via upload
1 parent f9dedcb commit cd25885

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

ciphers/ROT13Cipher.bat

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@echo off & setlocal enableDelayedExpansion
2+
3+
call :ROT13cipher "hello world"
4+
call :ROT13cipher "%$cipher%"
5+
6+
pause & exit
7+
8+
:ROT13cipher "string"
9+
set "$cipher="
10+
set "string=%~1"
11+
set "alpha=abcdefghijklmnopqrstuvwxyz "
12+
set "shift=nopqrstuvwxyzabcdefghijklm "
13+
14+
for /l %%b in (12,-1,0) do (
15+
set /a "string.length|=1<<%%b"
16+
for %%c in (!string.length!) do if "!string:~%%c,1!" equ "" (
17+
set /a "string.length&=~1<<%%b"
18+
)
19+
)
20+
21+
for /l %%i in (0,1,%string.length%) do for /l %%j in (0,1,26) do (
22+
if /i "!string:~%%i,1!" equ "!alpha:~%%j,1!" (
23+
set "$cipher=!$cipher!!shift:~%%j,1!"
24+
)
25+
)
26+
echo ROT13: %$cipher%
27+
goto :eof

ciphers/atbashCipher.bat

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@echo off & setlocal enableDelayedExpansion
2+
3+
call :atbashcipher "hello world"
4+
5+
pause & exit
6+
7+
:atbashcipher "string"
8+
set "$cipher="
9+
set "string=%~1"
10+
set "alpha=abcdefghijklmnopqrstuvwxyz "
11+
set "shift= zyxwvutsrqponmlkjihgfedcba"
12+
13+
for /l %%b in (12,-1,0) do (
14+
set /a "string.length|=1<<%%b"
15+
for %%c in (!string.length!) do if "!string:~%%c,1!" equ "" (
16+
set /a "string.length&=~1<<%%b"
17+
)
18+
)
19+
20+
for /l %%i in (0,1,%string.length%) do for /l %%j in (0,1,26) do (
21+
if /i "!string:~%%i,1!" equ "!alpha:~%%j,1!" (
22+
set "$cipher=!$cipher!!shift:~%%j,1!"
23+
)
24+
)
25+
echo ATBASH: %$cipher%
26+
goto :eof

ciphers/caesarCipher.bat

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@echo off & setlocal enableDelayedExpansion & mode 80,40
2+
3+
call :caesarcipher "hello world" 4
4+
5+
pause & exit
6+
7+
:caesarcipher "string" shiftLength
8+
set "$cipher="
9+
set "string=%~1"
10+
set "shift.length=%~2" & rem 0-26
11+
set "alpha=abcdefghijklmnopqrstuvwxyz "
12+
set "shift=!alpha:~%shift.length%!!alpha:~0,%shift.length%!"
13+
14+
for /l %%b in (12,-1,0) do (
15+
set /a "string.length|=1<<%%b"
16+
for %%c in (!string.length!) do if "!string:~%%c,1!" equ "" (
17+
set /a "string.length&=~1<<%%b"
18+
)
19+
)
20+
21+
for /l %%i in (0,1,%string.length%) do for /l %%j in (0,1,26) do (
22+
if /i "!string:~%%i,1!" equ "!alpha:~%%j,1!" (
23+
set "$cipher=!$cipher!!shift:~%%j,1!"
24+
)
25+
)
26+
echo Caesar Cipher: %$cipher%
27+
goto :eof

ciphers/vigenereCipher.bat

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
@echo off & setlocal enableDelayedExpansion
2+
3+
call :vigenerecipher "attack at dawn" "lemon"
4+
5+
pause & exit
6+
7+
:vigenerecipher "string" key
8+
set "$cipher="
9+
set "string=%~1"
10+
set "key=%~2"
11+
set "alpha=abcdefghijklmnopqrstuvwxyz"
12+
13+
set /a "string.length=0"
14+
for /l %%b in (8,-1,0) do (
15+
set /a "string.length|=1<<%%b"
16+
for %%c in (!string.length!) do if "!string:~%%c,1!" equ "" (
17+
set /a "string.length&=~1<<%%b"
18+
)
19+
)
20+
set /a "string.length+=1"
21+
for /l %%i in (1,1,4) do set "key=!key!!key!!key!!key!"
22+
set "key=!key:~0,%string.length%!"
23+
24+
set /a "string.length-=1"
25+
for /l %%i in (0,1,%string.length%) do (
26+
set "shift=-1"
27+
set "shiftalpha="
28+
for %%j in (a b c d e f g h j i k l m n o p q r s t u v w x y z) do (
29+
set /a "shift+=1"
30+
if /i "!key:~%%i,1!" equ "%%j" (
31+
for %%s in (!shift!) do (
32+
set "shiftalpha=!alpha:~%%s!!alpha:~0,%%s!"
33+
)
34+
)
35+
)
36+
for /l %%j in (0,1,25) do (
37+
if /i "!string:~%%i,1!" equ "!alpha:~%%j,1!" (
38+
set "$cipher=!$cipher!!shiftalpha:~%%j,1!"
39+
)
40+
)
41+
)
42+
43+
echo Vigenere Cipher: %$cipher%
44+
goto :eof

0 commit comments

Comments
 (0)