Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
35
Task/Caesar-cipher/Yabasic/caesar-cipher.basic
Normal file
35
Task/Caesar-cipher/Yabasic/caesar-cipher.basic
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
REM *** By changing the key and pattern, an encryption system that is difficult to break can be achieved. ***
|
||||
|
||||
text$ = "You are encouraged to solve this task according to the task description, using any language you may know."
|
||||
key$ = "desoxirribonucleic acid" // With a single character you get a Caesar encryption. With more characters the key is much more difficult to discover.
|
||||
CIPHER = 1 : DECIPHER = -1
|
||||
|
||||
print text$ : print
|
||||
encrypted$ = criptex$(text$, key$, CIPHER)
|
||||
a = open("cryptedText.txt", "w") : if a then print #a encrypted$ : close #a end if
|
||||
print encrypted$ : print
|
||||
print criptex$(encrypted$, key$, DECIPHER)
|
||||
|
||||
sub criptex$(text$, key$, mode)
|
||||
local i, k, delta, longtext, longPattern, longkey, pattern$, res$
|
||||
|
||||
pattern$ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 .,;:()-"
|
||||
|
||||
longPattern = len(pattern$)
|
||||
longtext = len(text$)
|
||||
longkey = len(key$)
|
||||
|
||||
for i = 1 to longtext
|
||||
k = k + 1 : if k > longkey k = 1
|
||||
delta = instr(pattern$, mid$(text$, i, 1))
|
||||
delta = delta + (mode * instr(pattern$, mid$(key$, k, 1)))
|
||||
if delta > longPattern then
|
||||
delta = delta - longPattern
|
||||
elseif delta < 1 then
|
||||
delta = longPattern + delta
|
||||
end if
|
||||
res$ = res$ + mid$(pattern$, delta, 1)
|
||||
next i
|
||||
|
||||
return res$
|
||||
end sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue