Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
56
Task/Caesar-cipher/XBasic/caesar-cipher.basic
Normal file
56
Task/Caesar-cipher/XBasic/caesar-cipher.basic
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
PROGRAM "caesarcipher"
|
||||
VERSION "0.0001"
|
||||
|
||||
DECLARE FUNCTION Entry()
|
||||
INTERNAL FUNCTION Encrypt$(p$, key%%)
|
||||
INTERNAL FUNCTION Decrypt$(p$, key%%)
|
||||
|
||||
FUNCTION Entry()
|
||||
txt$ = "The five boxing wizards jump quickly"
|
||||
key%% = 3
|
||||
PRINT "Original: "; txt$
|
||||
enc$ = Encrypt$(txt$, key%%)
|
||||
PRINT "Encrypted: "; enc$
|
||||
PRINT "Decrypted: "; Decrypt$(enc$, key%%)
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION Encrypt$(p$, key%%)
|
||||
e$ = p$ ' In order to avoid iterative concatenations
|
||||
FOR i = 0 TO LEN(p$) - 1
|
||||
t@@ = p${i} ' or (slower) t@@ = ASC(p$, i + 1)
|
||||
SELECT CASE TRUE
|
||||
CASE (t@@ >= 'A') AND (t@@ <= 'Z'):
|
||||
t@@ = t@@ + key@@
|
||||
IF t&& > 'Z' THEN
|
||||
t@@ = t@@ - 26
|
||||
END IF
|
||||
CASE (t@@ >= 'a') AND (t@@ <= 'z'):
|
||||
t@@ = t@@ + key%%
|
||||
IF t@@ > 'z' THEN
|
||||
t@@ = t@@ - 26
|
||||
END IF
|
||||
END SELECT
|
||||
e${i} = t@@
|
||||
NEXT i
|
||||
END FUNCTION e$
|
||||
|
||||
FUNCTION Decrypt$(p$, key%%)
|
||||
e$ = p$ ' In order to avoid iterative concatenations
|
||||
FOR i = 0 TO LEN(p$) - 1
|
||||
t@@ = p${i} ' or (slower) t@@ = ASC(p$, i + 1)
|
||||
SELECT CASE TRUE
|
||||
CASE (t@@ >= 'A') AND (t@@ <= 'Z'):
|
||||
t@@ = t@@ - key%%
|
||||
IF t@@ < 'A' THEN
|
||||
t@@ = t@@ + 26
|
||||
END IF
|
||||
CASE (t@@ >= 'a') AND (t@@ <= 'z'):
|
||||
t@@ = t@@ - key%%
|
||||
IF t@@ < 'a' THEN
|
||||
t@@ = t@@ + 26
|
||||
END IF
|
||||
END SELECT
|
||||
e${i} = t@@
|
||||
NEXT i
|
||||
END FUNCTION e$
|
||||
END PROGRAM
|
||||
Loading…
Add table
Add a link
Reference in a new issue