June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -10,7 +10,7 @@ The '''rot-13''' encoding is commonly known from the early days of
|
|||
|
||||
Many news reader and mail user agent programs have built-in '''rot-13''' encoder/decoders or have the ability to feed a message through any external utility script for performing this (or other) actions.
|
||||
|
||||
The definition of the rot-13 function is to simply replace every letter of the ASCII alphabet with the letter which is "rotated" 13 characters "around" the 26 letter alphabet from its normal cardinal position (wrapping around from '''z'''' to '''a''' as necessary).
|
||||
The definition of the rot-13 function is to simply replace every letter of the ASCII alphabet with the letter which is "rotated" 13 characters "around" the 26 letter alphabet from its normal cardinal position (wrapping around from '''z''' to '''a''' as necessary).
|
||||
|
||||
Thus the letters '''abc''' become '''nop''' and so on.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +1,38 @@
|
|||
buffer = &70 ; or anywhere in zero page that's good
|
||||
buffer = $fa ; or anywhere in zero page that's good
|
||||
maxpage = $95 ; if non-terminated that's bad
|
||||
|
||||
org &1900
|
||||
org $1900
|
||||
.rot13
|
||||
stx buffer
|
||||
sty buffer+1
|
||||
ldy #0
|
||||
.loop lda (buffer),y
|
||||
bne decode ; quit on ASCII 0
|
||||
rts
|
||||
.decode cmp #&7b ; high range
|
||||
bcs next
|
||||
cmp #&41 ; low range
|
||||
bcc next
|
||||
cmp #&4f
|
||||
bcc add13
|
||||
cmp #&5b
|
||||
bcc sub13
|
||||
cmp #&61
|
||||
bcc next
|
||||
cmp #&6f
|
||||
bcc add13
|
||||
bcs sub13 ; saves a byte over a jump
|
||||
.next iny
|
||||
jmp loop
|
||||
.add13 adc #13 ; we only get here via bcc; so clc not needed
|
||||
jmp storeit
|
||||
.sub13 sec
|
||||
sbc #13
|
||||
.storeit sta (buffer),y
|
||||
jmp next
|
||||
stx buffer
|
||||
sty buffer+1
|
||||
ldy #0
|
||||
beq readit
|
||||
.loop cmp #$7b ; high range
|
||||
bcs next ; >= {
|
||||
cmp #$41 ; low range
|
||||
bcc next ; < A
|
||||
cmp #$4e
|
||||
bcc add13 ; < N
|
||||
cmp #$5b
|
||||
bcc sub13set ; < [
|
||||
cmp #$61
|
||||
bcc next ; < a
|
||||
cmp #$6e
|
||||
bcs sub13 ; >= n
|
||||
.add13 adc #13 ; we only get here via bcc; so clc not needed
|
||||
bne storeit
|
||||
.sub13set sec ; because we got here via bcc; so sec is needed
|
||||
.sub13 sbc #13 ; we can get here via bcs; so sec not needed
|
||||
.storeit sta (buffer),y
|
||||
.next iny
|
||||
bne readit
|
||||
ldx buffer+1
|
||||
cpx maxpage
|
||||
beq done
|
||||
inx
|
||||
stx buffer+1
|
||||
.readit lda (buffer),y ; quit on ascii 0
|
||||
bne loop
|
||||
.done rts
|
||||
.end
|
||||
save "rot-13", rot13, end
|
||||
|
|
|
|||
2
Task/Rot-13/Applesoft-BASIC/rot-13.applesoft
Normal file
2
Task/Rot-13/Applesoft-BASIC/rot-13.applesoft
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
100HOME:INPUT"ENTER A STRING:";S$:FORL=1TOLEN(S$):I$=MID$(S$,L,1):LC=(ASC(I$)>95)*32:C$=CHR$(ASC(I$)-LC):IFC$>="A"ANDC$<="Z"THENC$=CHR$(ASC(C$)+13):C$=CHR$(ASC(C$)-26*(C$>"Z")):I$=CHR$(ASC(C$)+LC)
|
||||
110A$=A$+I$:NEXT:PRINTA$
|
||||
30
Task/Rot-13/Elena/rot-13.elena
Normal file
30
Task/Rot-13/Elena/rot-13.elena
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import system'routines.
|
||||
import extensions.
|
||||
|
||||
singleton rotConvertor
|
||||
{
|
||||
char convert(char ch)
|
||||
[
|
||||
if (($97 <= ch) && (ch <= $109) || ($65 <= ch) && (ch <= $77))
|
||||
[
|
||||
^ (ch toInt + 13) toChar
|
||||
].
|
||||
if (($110 <= ch) && (ch <= $122) || ($78 <= ch) && (ch <= $90))
|
||||
[
|
||||
^ (ch toInt - 13) toChar
|
||||
].
|
||||
|
||||
^ ch
|
||||
]
|
||||
|
||||
literal convert(literal s)
|
||||
= s selectBy(:ch)(rotConvertor convert(ch)); summarize(String new).
|
||||
}
|
||||
|
||||
program =
|
||||
[
|
||||
if ('program'arguments length > 1)
|
||||
[
|
||||
console printLine(rotConvertor convert('program'arguments[1])).
|
||||
]
|
||||
].
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
function rot13(c::Char)
|
||||
c in 'a':'z' ? 'a' + (c - 'a' + 13)%26 :
|
||||
c in 'A':'Z' ? 'A' + (c - 'A' + 13)%26 :
|
||||
c
|
||||
shft = islower(c) ? 'a' : 'A'
|
||||
isalpha(c) ? c = shft + (c - shft + 13) % 26 : c
|
||||
end
|
||||
|
||||
rot13(s::String) = map(rot13,s)
|
||||
rot13(str::AbstractString) = map(rot13, str)
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
.=trans: 'a..mn..z' => 'n..za..m', :ii
|
||||
print slurp.trans: ['A'..'Z','a'..'z'] => ['N'..'Z','A'..'M','n'..'z','a'..'m']
|
||||
|
|
|
|||
40
Task/Rot-13/PowerBASIC/rot-13.powerbasic
Normal file
40
Task/Rot-13/PowerBASIC/rot-13.powerbasic
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#COMPILE EXE
|
||||
#COMPILER PBWIN 9.05
|
||||
#DIM ALL
|
||||
|
||||
FUNCTION ROT13(BYVAL a AS STRING) AS STRING
|
||||
LOCAL p AS BYTE PTR
|
||||
LOCAL n AS BYTE, e AS BYTE
|
||||
LOCAL res AS STRING
|
||||
|
||||
res = a
|
||||
p = STRPTR(res)
|
||||
n = @p
|
||||
DO WHILE n
|
||||
SELECT CASE n
|
||||
CASE 65 TO 90
|
||||
e = 90
|
||||
n += 13
|
||||
CASE 97 TO 122
|
||||
e = 122
|
||||
n += 13
|
||||
CASE ELSE
|
||||
e = 255
|
||||
END SELECT
|
||||
|
||||
IF n > e THEN
|
||||
n -= 26
|
||||
END IF
|
||||
@p = n
|
||||
INCR p
|
||||
n = @p
|
||||
LOOP
|
||||
FUNCTION = res
|
||||
END FUNCTION
|
||||
|
||||
'testing:
|
||||
|
||||
FUNCTION PBMAIN () AS LONG
|
||||
#DEBUG PRINT ROT13("abc")
|
||||
#DEBUG PRINT ROT13("nop")
|
||||
END FUNCTION
|
||||
|
|
@ -1,13 +1,3 @@
|
|||
Function ROT13($String)
|
||||
{
|
||||
$Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
$Cipher = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"
|
||||
Foreach($Char in $String.ToCharArray())
|
||||
{
|
||||
If ( $Char -match "[A-Za-z]" )
|
||||
{ $NewString += $Cipher.Chars($Alphabet.IndexOf($Char)) }
|
||||
else
|
||||
{ $NewString += $Char }
|
||||
}
|
||||
Return $NewString
|
||||
}
|
||||
$e = "This is a test Guvf vf n grfg"
|
||||
|
||||
[char[]](0..64+78..90+65..77+91..96+110..122+97..109+123..255)[[char[]]$e] -join ""
|
||||
|
|
|
|||
|
|
@ -1,21 +1,20 @@
|
|||
#!/usr/bin/env python
|
||||
import string
|
||||
|
||||
TRANSLATION_TABLE = str.maketrans(
|
||||
string.ascii_uppercase + string.ascii_lowercase,
|
||||
string.ascii_uppercase[13:] + string.ascii_uppercase[:13] +
|
||||
string.ascii_lowercase[13:] + string.ascii_lowercase[:13]
|
||||
)
|
||||
|
||||
|
||||
def rot13(s):
|
||||
"""Implement the rot-13 encoding function: "rotate" each letter by the
|
||||
letter that's 13 steps from it (wrapping from z to a)
|
||||
"""
|
||||
return s.translate(
|
||||
string.maketrans(
|
||||
string.ascii_uppercase + string.ascii_lowercase,
|
||||
string.ascii_uppercase[13:] + string.ascii_uppercase[:13] +
|
||||
string.ascii_lowercase[13:] + string.ascii_lowercase[:13]
|
||||
)
|
||||
)
|
||||
"""Return the rot-13 encoding of s."""
|
||||
return s.translate(TRANSLATION_TABLE)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
"""Peform line-by-line rot-13 encoding on any files listed on our
|
||||
command line or act as a standard UNIX filter (if no arguments
|
||||
specified).
|
||||
"""
|
||||
import fileinput
|
||||
for line in fileinput.input():
|
||||
print rot13(line), # (Note the trailing comma; avoid double-spacing our output)!
|
||||
"""rot-13 encode the input files, or stdin if no files are provided."""
|
||||
import fileinput
|
||||
for line in fileinput.input():
|
||||
print(rot13(line), end="")
|
||||
|
|
|
|||
|
|
@ -1,21 +1,15 @@
|
|||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
import string
|
||||
def rot13(s):
|
||||
"""Implement the rot-13 encoding function: "rotate" each letter by the
|
||||
letter that's 13 steps from it (wrapping from z to a)
|
||||
"""
|
||||
return s.translate(
|
||||
str.maketrans(
|
||||
string.ascii_uppercase + string.ascii_lowercase,
|
||||
string.ascii_uppercase[13:] + string.ascii_uppercase[:13] +
|
||||
string.ascii_lowercase[13:] + string.ascii_lowercase[:13]
|
||||
)
|
||||
)
|
||||
if __name__ == "__main__":
|
||||
lets = string.ascii_lowercase
|
||||
key = {x:y for (x,y) in zip(lets[13:]+lets[:14], lets)}
|
||||
key.update({x.upper():key[x].upper() for x in key.keys()})
|
||||
encode = lambda x: ''.join((key.get(c,c) for c in x))
|
||||
if __name__ == '__main__':
|
||||
"""Peform line-by-line rot-13 encoding on any files listed on our
|
||||
command line or act as a standard UNIX filter (if no arguments
|
||||
specified).
|
||||
"""
|
||||
import fileinput
|
||||
for line in fileinput.input():
|
||||
print(rot13(line), end="")
|
||||
print(encode(line), end="")
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ for a = 1 to len(s)
|
|||
if char > "z" char = char(ascii(char) - 26) else char = letter ok
|
||||
ok
|
||||
ans = ans + char
|
||||
nex
|
||||
next
|
||||
see ans + nl
|
||||
|
|
|
|||
11
Task/Rot-13/Stata/rot-13.stata
Normal file
11
Task/Rot-13/Stata/rot-13.stata
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
function rot13(s) {
|
||||
u = ascii(s)
|
||||
i = selectindex(u:>64 :& u:<91)
|
||||
if (length(i)>0) u[i] = mod(u[i]:-52, 26):+65
|
||||
i = selectindex(u:>96 :& u:<123)
|
||||
if (length(i)>0) u[i] = mod(u[i]:-84, 26):+97
|
||||
return(char(u))
|
||||
}
|
||||
|
||||
rot13("Shall Not Perish")
|
||||
Funyy Abg Crevfu
|
||||
24
Task/Rot-13/Visual-Basic/rot-13-1.vb
Normal file
24
Task/Rot-13/Visual-Basic/rot-13-1.vb
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Function ROT13(ByVal a As String) As String
|
||||
Dim i As Long
|
||||
Dim n As Integer, e As Integer
|
||||
|
||||
ROT13 = a
|
||||
For i = 1 To Len(a)
|
||||
n = Asc(Mid$(a, i, 1))
|
||||
Select Case n
|
||||
Case 65 To 90
|
||||
e = 90
|
||||
n = n + 13
|
||||
Case 97 To 122
|
||||
e = 122
|
||||
n = n + 13
|
||||
Case Else
|
||||
e = 255
|
||||
End Select
|
||||
|
||||
If n > e Then
|
||||
n = n - 26
|
||||
End If
|
||||
Mid$(ROT13, i, 1) = Chr$(n)
|
||||
Next i
|
||||
End Function
|
||||
4
Task/Rot-13/Visual-Basic/rot-13-2.vb
Normal file
4
Task/Rot-13/Visual-Basic/rot-13-2.vb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Sub Main()
|
||||
Debug.Assert ROT13("abc") = "nop"
|
||||
Debug.Assert ROT13("nop") = "abc"
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue