Data update

This commit is contained in:
Ingy döt Net 2023-08-01 14:30:30 -07:00
parent 07c7092a52
commit 61b93a2cd1
313 changed files with 6160 additions and 346 deletions

View file

@ -0,0 +1,45 @@
100 A$ = "ATTACKATDAWN": GOSUB 160"REPORT
110 K$ = "BGWKZQPNDSIOAXEFCLUMTHYVR"
120 A$ = "FLEEATONCE": GOSUB 160"REPORT
130 K$ = " .'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123"
140 A$ = "THE INVASION WILL START ON THE FIRST OF JANUARY 2023.": GOSUB 160"REPORT
150 END
REM REPORT
160 GOSUB 200"ENCRYPT
165 PRINT M$M$"FOR "W" X "W" POLYBIUS:":M$ = CHR$ (13): FOR I = 1 TO W: PRINT , MID$ (K$,(I - 1) * W + 1,W): NEXT
170 PRINT "ENCRYPTED: "E$
180 GOSUB 300"DECRYPT
190 PRINT "DECRYPTED: "U$;: RETURN
REM ENCRYPT A$ RETURNS E$
200 GOSUB 400:L = LEN (A$):E$ = "":U$ = "": IF NOT L THEN RETURN
210 FOR I = 1 TO L
220 C = ASC ( MID$ (A$,I,1)): IF X(C) AND Y(C) THEN U$ = U$ + CHR$ (C)
230 NEXT I
240 L = LEN (U$): IF NOT L THEN RETURN
250 FOR I = 1 TO L:C = ASC ( MID$ (U$,I,1)):A(I) = X(C):A(I + L) = Y(C): NEXT I
260 FOR I = 1 TO L * 2 STEP 2:E$ = E$ + MID$ (K$,(A(I) - 1) * W + A(I + 1),1): NEXT I
270 RETURN
REM DECRYPT E$ RETURNS U$
300 GOSUB 400:L = LEN (E$):U$ = "": IF NOT L THEN RETURN
310 FOR I = 1 TO L:C = ASC ( MID$ (E$,I)):B(I * 2 - 1) = X(C):B(I * 2) = Y(C): NEXT I
320 FOR I = 1 TO L:U$ = U$ + MID$ (K$,(B(I) - 1) * W + B(L + I),1): NEXT I
330 RETURN
REM POLYBIUS K$ RETURNS X(255),Y(255)
400 IF K$ = P$ AND LEN (K$) THEN RETURN
410 IF XY THEN FOR I = 0 TO 255:X(I) = 0:Y(I) = 0: NEXT I
420 IF NOT XY THEN DIM X(255),Y(255),A(512),B(512):XY = 1
430 IF K$ = "" THEN FOR I = 1 TO 25:K$ = K$ + CHR$ (I + 64 + (I > 9)): NEXT I
440 L = LEN (K$):W = INT ( SQR (L - 1) + 1):I = 1:N = 1:K = ASC ("0")
450 FOR X = 1 TO W
460 FOR Y = 1 TO W
470 C$ = MID$ (K$,I,1): IF C$ = "" THEN FOR C = K TO 255: IF X(C) THEN NEXT C: STOP
480 IF C$ = "" THEN C$ = CHR$ (C):K$ = K$ + C$:K = C + 1
490 C = ASC (C$):Y(C) = Y:X(C) = X:I = I + 1: IF C$ = "J" THEN N = 0
500 NEXT Y,X
510 IF N THEN Y( ASC ("J")) = Y( ASC ("I")):X( ASC ("J")) = X( ASC ("I"))
520 P$ = K$
530 RETURN

View file

@ -0,0 +1,73 @@
function transcipher (cipher, message, decipher)
local message = message:gsub("%s+", ""):upper()
local xStr, yStr, s, char = "", "", ""
for pos = 1, #message do
char = message:sub(pos, pos)
for x = 1, #cipher do
for y = 1, #cipher[x] do
if cipher[x][y] == char then
s = s .. x .. y
xStr = xStr .. x
yStr = yStr .. y
end
end
end
end
if decipher then
xStr, yStr = s:sub(1, #s/2), s:sub(#s/2 + 1, #s)
else
s = xStr .. yStr
end
local result, x, y = ""
local limit = decipher and #s/2 or #s
local step = decipher and 1 or 2
for pos = 1, limit, step do
x = tonumber(s:sub(pos, pos))
y = decipher and
tonumber(s:sub(pos + #s/2, pos + #s/2)) or
tonumber(s:sub(pos + 1, pos + 1))
result = result .. cipher[x][y]
end
return result
end
local RCbifid = {
{"A", "B", "C", "D", "E"},
{"F", "G", "H", "I", "K"},
{"L", "M", "N", "O", "P"},
{"Q", "R", "S", "T", "U"},
{"V", "W", "X", "Y", "Z"}
}
local wikibifid = {
{"B", "G", "W", "K", "Z"},
{"Q", "P", "N", "D", "S"},
{"I", "O", "A", "X", "E"},
{"F", "C", "L", "U", "M"},
{"T", "H", "Y", "V", "R"}
}
local mybifid = {
{"A", "B", "C", "D", "E", "F"},
{"G", "H", "I", "J", "K", "L"},
{"M", "N", "O", "P", "Q", "R"},
{"S", "T", "U", "V", "W", "X"},
{"Y", "Z", "1", "2", "3", "4"},
{"5", "6", "7", "8", "9", "0"}
}
local testCases = {
{RCbifid, "ATTACKATDAWN"},
{wikibifid, "FLEEATONCE"},
{wikibifid, "ATTACKATDAWN",},
{mybifid, "The invasion will start on the first of January"}
}
local msg
for task, case in pairs(testCases) do
print("\nTask " .. task)
msg = transcipher(case[1], case[2])
print("Encoded message: " .. msg)
msg = transcipher(case[1], msg, true)
print("Decoded message: " .. msg)
end