tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
5
Task/Rot-13/0DESCRIPTION
Normal file
5
Task/Rot-13/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Implement a "rot-13" function (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program which acts like a common [[UNIX]] utility, performing a line-by-line rot-13 encoding of every line of input contained in each file listed on its command line, or (if no filenames are passed thereon) acting as a filter on its "standard input." (A number of UNIX scripting languages and utilities, such as ''awk'' and ''sed'' either default to processing files in this way or have command line switches or modules to easily implement these wrapper semantics, e.g., [[Perl]] and [[Python]]).
|
||||
|
||||
The "rot-13" encoding is commonly known from the early days of Usenet "Netnews" as a way of obfuscating text to prevent casual reading of [[wp:Spoiler (media)|spoiler]] or potentially offensive material. 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). Thus the letters "abc" become "nop" and so on. Technically rot-13 is a "monoalphabetic substitution cipher" with a trivial "key". A proper implementation should work on upper and lower case letters, preserve case, and pass all non-alphabetic characters in the input stream through without alteration.
|
||||
2
Task/Rot-13/1META.yaml
Normal file
2
Task/Rot-13/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Encryption
|
||||
31
Task/Rot-13/6502-Assembly/rot-13.6502
Normal file
31
Task/Rot-13/6502-Assembly/rot-13.6502
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
buffer = &70 ; or anywhere in zero page that's good
|
||||
|
||||
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
|
||||
20
Task/Rot-13/ACL2/rot-13.acl2
Normal file
20
Task/Rot-13/ACL2/rot-13.acl2
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(include-book "arithmetic-3/top" :dir :system)
|
||||
|
||||
(defun char-btn (c low high)
|
||||
(and (char>= c low)
|
||||
(char<= c high)))
|
||||
|
||||
(defun rot-13-cs (cs)
|
||||
(cond ((endp cs) nil)
|
||||
((or (char-btn (first cs) #\a #\m)
|
||||
(char-btn (first cs) #\A #\M))
|
||||
(cons (code-char (+ (char-code (first cs)) 13))
|
||||
(rot-13-cs (rest cs))))
|
||||
((or (char-btn (first cs) #\n #\z)
|
||||
(char-btn (first cs) #\N #\Z))
|
||||
(cons (code-char (- (char-code (first cs)) 13))
|
||||
(rot-13-cs (rest cs))))
|
||||
(t (cons (first cs) (rot-13-cs (rest cs))))))
|
||||
|
||||
(defun rot-13 (s)
|
||||
(coerce (rot-13-cs (coerce s 'list)) 'string))
|
||||
14
Task/Rot-13/ALGOL-68/rot-13.alg
Normal file
14
Task/Rot-13/ALGOL-68/rot-13.alg
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
BEGIN
|
||||
CHAR c;
|
||||
on logical file end(stand in, (REF FILE f)BOOL: (stop; SKIP));
|
||||
on line end(stand in, (REF FILE f)BOOL: (print(new line); FALSE));
|
||||
DO
|
||||
read(c);
|
||||
IF c >= "A" AND c <= "M" OR c >= "a" AND c <= "m" THEN
|
||||
c := REPR(ABS c + 13)
|
||||
ELIF c >= "N" AND c <= "Z" OR c >= "n" AND c <= "z" THEN
|
||||
c := REPR(ABS c - 13)
|
||||
FI;
|
||||
print(c)
|
||||
OD
|
||||
END # rot13 #
|
||||
22
Task/Rot-13/AWK/rot-13.awk
Normal file
22
Task/Rot-13/AWK/rot-13.awk
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
BEGIN {
|
||||
for(i=0; i < 256; i++) {
|
||||
amap[sprintf("%c", i)] = i
|
||||
}
|
||||
for(l=amap["a"]; l <= amap["z"]; l++) {
|
||||
rot13[l] = sprintf("%c", (((l-amap["a"])+13) % 26 ) + amap["a"])
|
||||
}
|
||||
FS = ""
|
||||
}
|
||||
{
|
||||
o = ""
|
||||
for(i=1; i <= NF; i++) {
|
||||
if ( amap[tolower($i)] in rot13 ) {
|
||||
c = rot13[amap[tolower($i)]]
|
||||
if ( tolower($i) != $i ) c = toupper(c)
|
||||
o = o c
|
||||
} else {
|
||||
o = o $i
|
||||
}
|
||||
}
|
||||
print o
|
||||
}
|
||||
40
Task/Rot-13/Ada/rot-13.ada
Normal file
40
Task/Rot-13/Ada/rot-13.ada
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
with Ada.Text_IO.Text_Streams; use Ada.Text_IO.Text_Streams;
|
||||
with Ada.Strings.Maps; use Ada.Strings.Maps;
|
||||
with Ada.Command_Line; use Ada.Command_Line;
|
||||
|
||||
procedure Rot_13 is
|
||||
|
||||
From_Sequence : Character_Sequence := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
Result_Sequence : Character_Sequence := "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM";
|
||||
Rot_13_Mapping : Character_Mapping := To_Mapping(From_Sequence, Result_Sequence);
|
||||
|
||||
In_Char : Character;
|
||||
Stdio : Stream_Access := Stream(Ada.Text_IO.Standard_Input);
|
||||
Stdout : Stream_Access := Stream(Ada.Text_Io.Standard_Output);
|
||||
Input : Ada.Text_Io.File_Type;
|
||||
|
||||
begin
|
||||
if Argument_Count > 0 then
|
||||
for I in 1..Argument_Count loop
|
||||
begin
|
||||
Ada.Text_Io.Open(File => Input, Mode => Ada.Text_Io.In_File, Name => Argument(I));
|
||||
Stdio := Stream(Input);
|
||||
while not Ada.Text_Io.End_Of_File(Input) loop
|
||||
In_Char :=Character'Input(Stdio);
|
||||
Character'Output(Stdout, Value(Rot_13_Mapping, In_Char));
|
||||
end loop;
|
||||
Ada.Text_IO.Close(Input);
|
||||
exception
|
||||
when Ada.Text_IO.Name_Error =>
|
||||
Ada.Text_Io.Put_Line(File => Ada.Text_Io.Standard_Error, Item => "File " & Argument(I) & " is not a file.");
|
||||
when Ada.Text_Io.Status_Error =>
|
||||
Ada.Text_Io.Put_Line(File => Ada.Text_Io.Standard_Error, Item => "File " & Argument(I) & " is already opened.");
|
||||
end;
|
||||
end loop;
|
||||
else
|
||||
while not Ada.Text_Io.End_Of_File loop
|
||||
In_Char :=Character'Input(Stdio);
|
||||
Character'Output(Stdout, Value(Rot_13_Mapping, In_Char));
|
||||
end loop;
|
||||
end if;
|
||||
end Rot_13;
|
||||
3
Task/Rot-13/AppleScript/rot-13-1.applescript
Normal file
3
Task/Rot-13/AppleScript/rot-13-1.applescript
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
to rot13(textString)
|
||||
do shell script "tr a-zA-Z n-za-mN-ZA-M <<<" & quoted form of textString
|
||||
end rot13
|
||||
13
Task/Rot-13/AppleScript/rot-13-2.applescript
Normal file
13
Task/Rot-13/AppleScript/rot-13-2.applescript
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
to rot13(textString)
|
||||
local outChars
|
||||
set outChars to {}
|
||||
repeat with ch in (characters of textString)
|
||||
if (ch >= "a" and ch <= "m") or (ch >= "A" and ch <= "M") then
|
||||
set ch to character id (id of ch + 13)
|
||||
else if (ch >= "n" and ch <= "z") or (ch >= "N" and ch <= "Z") then
|
||||
set ch to character id (id of ch - 13)
|
||||
end
|
||||
set end of outChars to ch
|
||||
end
|
||||
return outChars as text
|
||||
end rot13
|
||||
1
Task/Rot-13/AppleScript/rot-13-3.applescript
Normal file
1
Task/Rot-13/AppleScript/rot-13-3.applescript
Normal file
|
|
@ -0,0 +1 @@
|
|||
rot13("nowhere ABJURER")
|
||||
28
Task/Rot-13/AutoHotkey/rot-13.ahk
Normal file
28
Task/Rot-13/AutoHotkey/rot-13.ahk
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
Str0=Hello, This is a sample text with 1 2 3 or other digits!@#$^&*()-_=
|
||||
Str1 := Rot13(Str0)
|
||||
Str2 := Rot13(Str1)
|
||||
MsgBox % Str0 "`n" Str1 "`n" Str2
|
||||
|
||||
Rot13(string)
|
||||
{
|
||||
Loop Parse, string
|
||||
{
|
||||
char := Asc(A_LoopField)
|
||||
; o is 'A' code if it is an uppercase letter, and 'a' code if it is a lowercase letter
|
||||
o := Asc("A") * (Asc("A") <= char && char <= Asc("Z")) + Asc("a") * (Asc("a") <= char && char <= Asc("z"))
|
||||
If (o > 0)
|
||||
{
|
||||
; Set between 0 and 25, add rotation factor, modulus alphabet size
|
||||
char := Mod(char - o + 13, 26)
|
||||
; Transform back to char, upper or lower
|
||||
char := Chr(char + o)
|
||||
}
|
||||
Else
|
||||
{
|
||||
; Non alphabetic, unchanged
|
||||
char := A_LoopField
|
||||
}
|
||||
rStr .= char
|
||||
}
|
||||
Return rStr
|
||||
}
|
||||
17
Task/Rot-13/BASIC/rot-13.basic
Normal file
17
Task/Rot-13/BASIC/rot-13.basic
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
CLS
|
||||
INPUT "Enter a string: ", s$
|
||||
ans$ = ""
|
||||
FOR a = 1 TO LEN(s$)
|
||||
letter$ = MID$(s$, a, 1)
|
||||
IF letter$ >= "A" AND letter$ <= "Z" THEN
|
||||
char$ = CHR$(ASC(letter$) + 13)
|
||||
IF char$ > "Z" THEN char$ = CHR$(ASC(char$) - 26)
|
||||
ELSEIF letter$ >= "a" AND letter$ <= "z" THEN
|
||||
char$ = CHR$(ASC(letter$) + 13)
|
||||
IF char$ > "z" THEN char$ = CHR$(ASC(char$) - 26)
|
||||
ELSE
|
||||
char$ = letter$
|
||||
END IF
|
||||
ans$ = ans$ + char$
|
||||
NEXT a
|
||||
PRINT ans$
|
||||
22
Task/Rot-13/BBC-BASIC/rot-13.bbc
Normal file
22
Task/Rot-13/BBC-BASIC/rot-13.bbc
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
REPEAT
|
||||
INPUT A$
|
||||
PRINT FNrot13(A$)
|
||||
UNTIL FALSE
|
||||
END
|
||||
|
||||
DEF FNrot13(A$)
|
||||
LOCAL A%,B$,C$
|
||||
IF A$="" THEN =""
|
||||
FOR A%=1 TO LEN A$
|
||||
C$=MID$(A$,A%,1)
|
||||
IF C$<"A" OR (C$>"Z" AND C$<"a") OR C$>"z" THEN
|
||||
B$=B$+C$
|
||||
ELSE
|
||||
IF (ASC(C$) AND &DF)<ASC("N") THEN
|
||||
B$=B$+CHR$(ASC(C$)+13)
|
||||
ELSE
|
||||
B$=B$+CHR$(ASC(C$)-13)
|
||||
ENDIF
|
||||
ENDIF
|
||||
NEXT A%
|
||||
=B$
|
||||
4
Task/Rot-13/Befunge/rot-13.bf
Normal file
4
Task/Rot-13/Befunge/rot-13.bf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
~:"z"`#v_:"m"`#v_:"`"` |>
|
||||
:"Z"`#v_:"M"`#v_:"@"`|>
|
||||
: 0 `#v_@v-6-7< >
|
||||
, < <+6+7 <<v
|
||||
4
Task/Rot-13/Burlesque/rot-13.blq
Normal file
4
Task/Rot-13/Burlesque/rot-13.blq
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
blsq ) "HELLO WORLD"{{'A'Zr\\/Fi}m[13?+26.%'A'Zr\\/si}ww
|
||||
"URYYB JBEYQ"
|
||||
blsq ) "URYYB JBEYQ"{{'A'Zr\\/Fi}m[13?+26.%'A'Zr\\/si}ww
|
||||
"HELLO WORLD"
|
||||
77
Task/Rot-13/C++/rot-13-1.cpp
Normal file
77
Task/Rot-13/C++/rot-13-1.cpp
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
// the rot13 function
|
||||
std::string rot13(std::string s)
|
||||
{
|
||||
static std::string const
|
||||
lcalph = "abcdefghijklmnopqrstuvwxyz",
|
||||
ucalph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
std::string result;
|
||||
std::string::size_type pos;
|
||||
|
||||
result.reserve(s.length());
|
||||
|
||||
for (std::string::iterator it = s.begin(); it != s.end(); ++it)
|
||||
{
|
||||
if ( (pos = lcalph.find(*it)) != std::string::npos )
|
||||
result.push_back(lcalph[(pos+13) % 26]);
|
||||
else if ( (pos = ucalph.find(*it)) != std::string::npos )
|
||||
result.push_back(ucalph[(pos+13) % 26]);
|
||||
else
|
||||
result.push_back(*it);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// function to output the rot13 of a file on std::cout
|
||||
// returns false if an error occurred processing the file, true otherwise
|
||||
// on entry, the argument is must be open for reading
|
||||
int rot13_stream(std::istream& is)
|
||||
{
|
||||
std::string line;
|
||||
while (std::getline(is, line))
|
||||
{
|
||||
if (!(std::cout << rot13(line) << "\n"))
|
||||
return false;
|
||||
}
|
||||
return is.eof();
|
||||
}
|
||||
|
||||
// the main program
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc == 1) // no arguments given
|
||||
return rot13_stream(std::cin)? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
|
||||
std::ifstream file;
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
file.open(argv[i], std::ios::in);
|
||||
if (!file)
|
||||
{
|
||||
std::cerr << argv[0] << ": could not open for reading: " << argv[i] << "\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (!rot13_stream(file))
|
||||
{
|
||||
if (file.eof())
|
||||
// no error occurred for file, so the error must have been in output
|
||||
std::cerr << argv[0] << ": error writing to stdout\n";
|
||||
else
|
||||
std::cerr << argv[0] << ": error reading from " << argv[i] << "\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
file.clear();
|
||||
file.close();
|
||||
if (!file)
|
||||
std::cerr << argv[0] << ": warning: closing failed for " << argv[i] << "\n";
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
41
Task/Rot-13/C++/rot-13-2.cpp
Normal file
41
Task/Rot-13/C++/rot-13-2.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <boost/iostreams/concepts.hpp> // output_filter
|
||||
#include <boost/iostreams/operations.hpp> // put
|
||||
#include <boost/iostreams/filtering_stream.hpp>
|
||||
#include <fstream>
|
||||
namespace io = boost::iostreams;
|
||||
|
||||
class rot_output_filter : public io::output_filter
|
||||
{
|
||||
public:
|
||||
explicit rot_output_filter(int r=13):rotby(r),negrot(alphlen-r){};
|
||||
|
||||
template<typename Sink>
|
||||
bool put(Sink& dest, int c){
|
||||
char uc = toupper(c);
|
||||
|
||||
if(('A' <= uc) && (uc <= ('Z'-rotby)))
|
||||
c = c + rotby;
|
||||
else if ((('Z'-rotby) <= uc) && (uc <= 'Z'))
|
||||
c = c - negrot;
|
||||
return boost::iostreams::put(dest, c);
|
||||
};
|
||||
private:
|
||||
static const int alphlen = 26;
|
||||
const int rotby;
|
||||
const int negrot;
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
io::filtering_ostream out;
|
||||
out.push(rot_output_filter(13));
|
||||
out.push(std::cout);
|
||||
|
||||
if (argc == 1) out << std::cin.rdbuf();
|
||||
else for(int i = 1; i < argc; ++i){
|
||||
std::ifstream in(argv[i]);
|
||||
out << in.rdbuf();
|
||||
}
|
||||
}
|
||||
44
Task/Rot-13/C/rot-13.c
Normal file
44
Task/Rot-13/C/rot-13.c
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<ctype.h>
|
||||
|
||||
#define MAXLINE 1024
|
||||
|
||||
char *rot13(char *s)
|
||||
{
|
||||
char *p=s;
|
||||
int upper;
|
||||
|
||||
while(*p) {
|
||||
upper=toupper(*p);
|
||||
if(upper>='A' && upper<='M') *p+=13;
|
||||
else if(upper>='N' && upper<='Z') *p-=13;
|
||||
++p;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void rot13file(FILE *fp)
|
||||
{
|
||||
static char line[MAXLINE];
|
||||
while(fgets(line, MAXLINE, fp)>0) fputs(rot13(line), stdout);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n;
|
||||
FILE *fp;
|
||||
|
||||
if(argc>1) {
|
||||
for(n=1; n<argc; ++n) {
|
||||
if(!(fp=fopen(argv[n], "r"))) {
|
||||
fprintf(stderr, "ERROR: Couldn\'t read %s\n", argv[n]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
rot13file(fp);
|
||||
fclose(fp);
|
||||
}
|
||||
} else rot13file(stdin);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
12
Task/Rot-13/Clojure/rot-13-1.clj
Normal file
12
Task/Rot-13/Clojure/rot-13-1.clj
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
(defn rot-13 [c]
|
||||
(let [i (int c)]
|
||||
(cond
|
||||
(or (and (>= i (int \a)) (<= i (int \m)))
|
||||
(and (>= i (int \A)) (<= i (int \M))))
|
||||
(char (+ i 13))
|
||||
(or (and (>= i (int \n)) (<= i (int \z)))
|
||||
(and (>= i (int \N)) (<= i (int \Z))))
|
||||
(char (- i 13))
|
||||
:else c)))
|
||||
|
||||
(apply str (map rot-13 "abcxyzABCXYZ")) ;; output "nopklmNOPKLM"
|
||||
7
Task/Rot-13/Clojure/rot-13-2.clj
Normal file
7
Task/Rot-13/Clojure/rot-13-2.clj
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(let [A (into #{} "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
A-map (zipmap A (take 52 (drop 26 (cycle A))))]
|
||||
|
||||
(defn rot13[in-str]
|
||||
(reduce str (map #(if (A %1) (A-map %1) %1) in-str))))
|
||||
|
||||
(rot13 "The Quick Brown Fox Jumped Over The Lazy Dog!") ;; produces "Gur Dhvpx Oebja Sbk Whzcrq Bire Gur Ynml Qbt!"
|
||||
13
Task/Rot-13/Common-Lisp/rot-13-1.lisp
Normal file
13
Task/Rot-13/Common-Lisp/rot-13-1.lisp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
(defconstant +alphabet+
|
||||
'(#\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))
|
||||
|
||||
(defun rot13 (s)
|
||||
(map 'string
|
||||
(lambda (c &aux (n (position (char-upcase c) +alphabet+)))
|
||||
(if n
|
||||
(funcall
|
||||
(if (lower-case-p c) #'char-downcase #'identity)
|
||||
(nth (mod (+ 13 n) 26) +alphabet+))
|
||||
c))
|
||||
s))
|
||||
12
Task/Rot-13/Common-Lisp/rot-13-2.lisp
Normal file
12
Task/Rot-13/Common-Lisp/rot-13-2.lisp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
(defun rot13 (string)
|
||||
(map 'string
|
||||
(lambda (char &aux (code (char-code char)))
|
||||
(if (alpha-char-p char)
|
||||
(if (> (- code (char-code (if (upper-case-p char)
|
||||
#\A #\a))) 12)
|
||||
(code-char (- code 13))
|
||||
(code-char (+ code 13)))
|
||||
char))
|
||||
string))
|
||||
|
||||
(rot13 "Moron") ; -> "Zbeba"
|
||||
12
Task/Rot-13/D/rot-13-1.d
Normal file
12
Task/Rot-13/D/rot-13-1.d
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import std.stdio;
|
||||
import std.ascii: letters, U = uppercase, L = lowercase;
|
||||
import std.string: makeTrans, translate;
|
||||
|
||||
immutable r13 = makeTrans(letters,
|
||||
//U[13 .. $] ~ U[0 .. 13] ~
|
||||
U[13 .. U.length] ~ U[0 .. 13] ~
|
||||
L[13 .. L.length] ~ L[0 .. 13]);
|
||||
|
||||
void main() {
|
||||
writeln("This is the 1st test!".translate(r13, null));
|
||||
}
|
||||
21
Task/Rot-13/D/rot-13-2.d
Normal file
21
Task/Rot-13/D/rot-13-2.d
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import std.stdio, std.string, std.traits;
|
||||
|
||||
pure S rot13(S)(in S s) if (isSomeString!S) {
|
||||
return rot(s, 13);
|
||||
}
|
||||
|
||||
pure S rot(S)(in S s, in int key) if (isSomeString!S) {
|
||||
auto r = s.dup;
|
||||
|
||||
foreach (i, ref c; r) {
|
||||
if ('a' <= c && c <= 'z')
|
||||
c = ((c - 'a' + key) % 26 + 'a');
|
||||
else if ('A' <= c && c <= 'Z')
|
||||
c = ((c - 'A' + key) % 26 + 'A');
|
||||
}
|
||||
return cast(S) r;
|
||||
}
|
||||
|
||||
void main() {
|
||||
"Gur Dhvpx Oebja Sbk Whzcf Bire Gur Ynml Qbt!".rot13().writeln();
|
||||
}
|
||||
12
Task/Rot-13/E/rot-13.e
Normal file
12
Task/Rot-13/E/rot-13.e
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
pragma.enable("accumulator")
|
||||
|
||||
var rot13Map := [].asMap()
|
||||
for a in ['a', 'A'] {
|
||||
for i in 0..!26 {
|
||||
rot13Map with= (a + i, E.toString(a + (i + 13) % 26))
|
||||
}
|
||||
}
|
||||
|
||||
def rot13(s :String) {
|
||||
return accum "" for c in s { _ + rot13Map.fetch(c, fn{ c }) }
|
||||
}
|
||||
6
Task/Rot-13/Erlang/rot-13.erl
Normal file
6
Task/Rot-13/Erlang/rot-13.erl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
rot13(Str) ->
|
||||
F = fun(C) when (C >= $A andalso C =< $M); (C >= $a andalso C =< $m) -> C + 13;
|
||||
(C) when (C >= $N andalso C =< $Z); (C >= $n andalso C =< $z) -> C - 13;
|
||||
(C) -> C
|
||||
end,
|
||||
lists:map(F, Str).
|
||||
39
Task/Rot-13/Euphoria/rot-13.euphoria
Normal file
39
Task/Rot-13/Euphoria/rot-13.euphoria
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
include std/types.e
|
||||
include std/text.e
|
||||
|
||||
atom FALSE = 0
|
||||
atom TRUE = not FALSE
|
||||
|
||||
function Rot13( object oStuff )
|
||||
integer iOffset
|
||||
integer bIsUpper
|
||||
object oResult
|
||||
sequence sAlphabet = "abcdefghijklmnopqrstuvwxyz"
|
||||
if sequence(oStuff) then
|
||||
oResult = repeat( 0, length( oStuff ) )
|
||||
for i = 1 to length( oStuff ) do
|
||||
oResult[ i ] = Rot13( oStuff[ i ] )
|
||||
end for
|
||||
else
|
||||
bIsUpper = FALSE
|
||||
if t_upper( oStuff ) then
|
||||
bIsUpper = TRUE
|
||||
oStuff = lower( oStuff )
|
||||
end if
|
||||
iOffset = find( oStuff, sAlphabet )
|
||||
if iOffset != 0 then
|
||||
iOffset += 13
|
||||
iOffset = remainder( iOffset, 26 )
|
||||
if iOffset = 0 then iOffset = 1 end if
|
||||
oResult = sAlphabet[iOffset]
|
||||
if bIsUpper then
|
||||
oResult = upper(oResult)
|
||||
end if
|
||||
else
|
||||
oResult = oStuff --sprintf( "%s", oStuff )
|
||||
end if
|
||||
end if
|
||||
return oResult
|
||||
end function
|
||||
|
||||
puts( 1, Rot13( "abjurer NOWHERE." ) & "\n" )
|
||||
1
Task/Rot-13/FALSE/rot-13.false
Normal file
1
Task/Rot-13/FALSE/rot-13.false
Normal file
|
|
@ -0,0 +1 @@
|
|||
[^$1+][$32|$$'z>'a@>|$[\%]?~[13\'m>[_]?+]?,]#%
|
||||
24
Task/Rot-13/Factor/rot-13.factor
Normal file
24
Task/Rot-13/Factor/rot-13.factor
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#! /usr/bin/env factor
|
||||
|
||||
USING: kernel io ascii math combinators sequences ;
|
||||
IN: rot13
|
||||
|
||||
: rot-base ( ch ch -- ch ) [ - 13 + 26 mod ] keep + ;
|
||||
|
||||
: rot13-ch ( ch -- ch )
|
||||
{
|
||||
{ [ dup letter? ] [ CHAR: a rot-base ] }
|
||||
{ [ dup LETTER? ] [ CHAR: A rot-base ] }
|
||||
[ ]
|
||||
}
|
||||
cond ;
|
||||
|
||||
: rot13 ( str -- str ) [ rot13-ch ] map ;
|
||||
|
||||
: main ( -- )
|
||||
[ readln dup ]
|
||||
[ rot13 print flush ]
|
||||
while
|
||||
drop ;
|
||||
|
||||
MAIN: main
|
||||
35
Task/Rot-13/Fantom/rot-13.fantom
Normal file
35
Task/Rot-13/Fantom/rot-13.fantom
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
class Rot13
|
||||
{
|
||||
static Str rot13 (Str input)
|
||||
{
|
||||
Str result := ""
|
||||
input.each |Int c|
|
||||
{
|
||||
if ((c.lower >= 'a') && (c.lower <= 'm'))
|
||||
result += (c+13).toChar
|
||||
else if ((c.lower >= 'n') && (c.lower <= 'z'))
|
||||
result += (c-13).toChar
|
||||
else
|
||||
result += c.toChar
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public static Void main (Str[] args)
|
||||
{
|
||||
if (args.size == 1)
|
||||
{ // process each line of given file
|
||||
Str filename := args[0]
|
||||
File(filename.toUri).eachLine |Str line|
|
||||
{
|
||||
echo (rot13(line))
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo ("Test:")
|
||||
Str text := "abcstuABCSTU123!+-"
|
||||
echo ("Text $text becomes ${rot13(text)}")
|
||||
}
|
||||
}
|
||||
}
|
||||
5
Task/Rot-13/Forth/rot-13-1.fth
Normal file
5
Task/Rot-13/Forth/rot-13-1.fth
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
: r13 ( c -- o )
|
||||
dup 32 or \ tolower
|
||||
dup [char] a [char] z 1+ within if
|
||||
[char] m > if -13 else 13 then +
|
||||
else drop then ;
|
||||
21
Task/Rot-13/Forth/rot-13-2.fth
Normal file
21
Task/Rot-13/Forth/rot-13-2.fth
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
: ,chars ( end start -- )
|
||||
do i c, loop ;
|
||||
|
||||
: xlate create does> ( c -- c' ) + c@ ;
|
||||
|
||||
xlate rot13
|
||||
char A 0 ,chars
|
||||
char Z 1+ char N ,chars
|
||||
char N char A ,chars
|
||||
char a char Z 1+ ,chars
|
||||
char z 1+ char n ,chars
|
||||
char n char a ,chars
|
||||
256 char z 1+ ,chars
|
||||
|
||||
: rot13-string ( addr len -- )
|
||||
over + swap do i c@ rot13 i c! loop ;
|
||||
|
||||
: .rot13" ( string -- )
|
||||
[char] " parse 2dup rot13-string type ;
|
||||
|
||||
.rot13" abjurer NOWHERE" \ nowhere ABJURER
|
||||
58
Task/Rot-13/Fortran/rot-13-1.f
Normal file
58
Task/Rot-13/Fortran/rot-13-1.f
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
program test_rot_13
|
||||
|
||||
implicit none
|
||||
integer, parameter :: len_max = 256
|
||||
integer, parameter :: unit = 10
|
||||
character (len_max) :: file
|
||||
character (len_max) :: fmt
|
||||
character (len_max) :: line
|
||||
integer :: arg
|
||||
integer :: arg_max
|
||||
integer :: iostat
|
||||
|
||||
write (fmt, '(a, i0, a)') '(a', len_max, ')'
|
||||
arg_max = iargc ()
|
||||
if (arg_max > 0) then
|
||||
! Encode all files listed on the command line.
|
||||
do arg = 1, arg_max
|
||||
call getarg (arg, file)
|
||||
open (unit, file = file, iostat = iostat)
|
||||
if (iostat /= 0) cycle
|
||||
do
|
||||
read (unit, fmt = fmt, iostat = iostat) line
|
||||
if (iostat /= 0) exit
|
||||
write (*, '(a)') trim (rot_13 (line))
|
||||
end do
|
||||
close (unit)
|
||||
end do
|
||||
else
|
||||
! Encode standard input.
|
||||
do
|
||||
read (*, fmt = fmt, iostat = iostat) line
|
||||
if (iostat /= 0) exit
|
||||
write (*, '(a)') trim (rot_13 (line))
|
||||
end do
|
||||
end if
|
||||
|
||||
contains
|
||||
|
||||
function rot_13 (input) result (output)
|
||||
|
||||
implicit none
|
||||
character (len_max), intent (in) :: input
|
||||
character (len_max) :: output
|
||||
integer :: i
|
||||
|
||||
output = input
|
||||
do i = 1, len_trim (output)
|
||||
select case (output (i : i))
|
||||
case ('A' : 'M', 'a' : 'm')
|
||||
output (i : i) = char (ichar (output (i : i)) + 13)
|
||||
case ('N' : 'Z', 'n' : 'z')
|
||||
output (i : i) = char (ichar (output (i : i)) - 13)
|
||||
end select
|
||||
end do
|
||||
|
||||
end function rot_13
|
||||
|
||||
end program test_rot_13
|
||||
12
Task/Rot-13/Fortran/rot-13-2.f
Normal file
12
Task/Rot-13/Fortran/rot-13-2.f
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
> cat foo.txt
|
||||
foo
|
||||
> cat bar.txt
|
||||
bar
|
||||
> ./rot_13 foo.txt bar.txt
|
||||
sbb
|
||||
one
|
||||
> ./rot_13 < foo.txt
|
||||
sbb
|
||||
> cat foo.txt bar.txt | ./rot_13
|
||||
sbb
|
||||
one
|
||||
27
Task/Rot-13/GAP/rot-13.gap
Normal file
27
Task/Rot-13/GAP/rot-13.gap
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
rot13 := function(s)
|
||||
local upper, lower, c, n, t;
|
||||
upper := "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
lower := "abcdefghijklmnopqrstuvwxyz";
|
||||
t := [ ];
|
||||
for c in s do
|
||||
n := Position(upper, c);
|
||||
if n <> fail then
|
||||
Add(t, upper[((n+12) mod 26) + 1]);
|
||||
else
|
||||
n := Position(lower, c);
|
||||
if n <> fail then
|
||||
Add(t, lower[((n+12) mod 26) + 1]);
|
||||
else
|
||||
Add(t, c);
|
||||
fi;
|
||||
fi;
|
||||
od;
|
||||
return t;
|
||||
end;
|
||||
|
||||
a := "England expects that every man will do his duty";
|
||||
# "England expects that every man will do his duty"
|
||||
b := rot13(a);
|
||||
# "Ratynaq rkcrpgf gung rirel zna jvyy qb uvf qhgl"
|
||||
c := rot13(b);
|
||||
# "England expects that every man will do his duty"
|
||||
16
Task/Rot-13/GML/rot-13-1.gml
Normal file
16
Task/Rot-13/GML/rot-13-1.gml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#define rot13
|
||||
{
|
||||
out = '';
|
||||
for (x = 1; x <= string_length(argument0); x += 1) {
|
||||
working = ord(string_char_at(argument0, x));
|
||||
if ((working > 64) && (working < 91)) {
|
||||
working += 13;
|
||||
if (working > 90) working -= 26;
|
||||
} else if ((working > 96) && (working < 123)) {
|
||||
working += 13;
|
||||
if (working > 122) working -= 26;
|
||||
}
|
||||
out = out + chr(working);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
1
Task/Rot-13/GML/rot-13-2.gml
Normal file
1
Task/Rot-13/GML/rot-13-2.gml
Normal file
|
|
@ -0,0 +1 @@
|
|||
show_message(rot13("My dog has fleas!"));
|
||||
14
Task/Rot-13/GW-BASIC/rot-13.gw-basic
Normal file
14
Task/Rot-13/GW-BASIC/rot-13.gw-basic
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
10 INPUT "Enter a string: ",A$
|
||||
20 GOSUB 50
|
||||
30 PRINT B$
|
||||
40 END
|
||||
50 FOR I=1 TO LEN(A$)
|
||||
60 N=ASC(MID$(A$,I,1))
|
||||
70 E=255
|
||||
80 IF N>64 AND N<91 THEN E=90 ' uppercase
|
||||
90 IF N>96 AND N<123 THEN E=122 ' lowercase
|
||||
100 IF E<255 THEN N=N+13
|
||||
110 IF N>E THEN N=N-26
|
||||
120 B$=B$+CHR$(N)
|
||||
130 NEXT
|
||||
140 RETURN
|
||||
2
Task/Rot-13/Gema/rot-13.gema
Normal file
2
Task/Rot-13/Gema/rot-13.gema
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/[a-mA-M]/=@int-char{@add{@char-int{$1};13}}
|
||||
/[n-zN-Z]/=@int-char{@sub{@char-int{$1};13}}
|
||||
23
Task/Rot-13/Go/rot-13.go
Normal file
23
Task/Rot-13/Go/rot-13.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func rot13char(c rune) rune {
|
||||
if c >= 'a' && c <= 'm' || c >= 'A' && c <= 'M' {
|
||||
return c + 13
|
||||
} else if c >= 'n' && c <= 'z' || c >= 'N' && c <= 'Z' {
|
||||
return c - 13
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func rot13(s string) string {
|
||||
return strings.Map(rot13char, s)
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(rot13("nowhere ABJURER"))
|
||||
}
|
||||
12
Task/Rot-13/Groovy/rot-13-1.groovy
Normal file
12
Task/Rot-13/Groovy/rot-13-1.groovy
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
def rot13 = { String s ->
|
||||
(s as List).collect { ch ->
|
||||
switch (ch) {
|
||||
case ('a'..'m') + ('A'..'M'):
|
||||
return (((ch as char) + 13) as char)
|
||||
case ('n'..'z') + ('N'..'Z'):
|
||||
return (((ch as char) - 13) as char)
|
||||
default:
|
||||
return ch
|
||||
}
|
||||
}.inject ("") { string, ch -> string += ch}
|
||||
}
|
||||
1
Task/Rot-13/Groovy/rot-13-2.groovy
Normal file
1
Task/Rot-13/Groovy/rot-13-2.groovy
Normal file
|
|
@ -0,0 +1 @@
|
|||
println rot13("Noyr jnf V, 'rer V fnj Ryon.")
|
||||
7
Task/Rot-13/Haskell/rot-13-1.hs
Normal file
7
Task/Rot-13/Haskell/rot-13-1.hs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import Data.Char
|
||||
|
||||
rot13 :: Char -> Char
|
||||
rot13 c
|
||||
| toLower c >= 'a' && toLower c <= 'm' = chr (ord c + 13)
|
||||
| toLower c >= 'n' && toLower c <= 'z' = chr (ord c - 13)
|
||||
| otherwise = c
|
||||
23
Task/Rot-13/Haskell/rot-13-2.hs
Normal file
23
Task/Rot-13/Haskell/rot-13-2.hs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import System.Environment
|
||||
import System.IO
|
||||
import System.Directory
|
||||
import Control.Monad
|
||||
|
||||
hInteract :: (String -> String) -> Handle -> Handle -> IO ()
|
||||
hInteract f hIn hOut =
|
||||
hGetContents hIn >>= hPutStr hOut . f
|
||||
|
||||
processByTemp :: (Handle -> Handle -> IO ()) -> String -> IO ()
|
||||
processByTemp f name = do
|
||||
hIn <- openFile name ReadMode
|
||||
let tmp = name ++ "$"
|
||||
hOut <- openFile tmp WriteMode
|
||||
f hIn hOut
|
||||
hClose hIn
|
||||
hClose hOut
|
||||
removeFile name
|
||||
renameFile tmp name
|
||||
|
||||
process :: (Handle -> Handle -> IO ()) -> [String] -> IO ()
|
||||
process f [] = f stdin stdout
|
||||
process f ns = mapM_ (processByTemp f) ns
|
||||
3
Task/Rot-13/Haskell/rot-13-3.hs
Normal file
3
Task/Rot-13/Haskell/rot-13-3.hs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
main = do
|
||||
names <- getArgs
|
||||
process (hInteract (map rot13)) names
|
||||
16
Task/Rot-13/HicEst/rot-13.hicest
Normal file
16
Task/Rot-13/HicEst/rot-13.hicest
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
CHARACTER c, txt='abc? XYZ!', cod*100
|
||||
|
||||
DO i = 1, LEN_TRIM(txt)
|
||||
c = txt(i)
|
||||
n = ICHAR(txt(i))
|
||||
IF( (c >= 'a') * (c <= 'm') + (c >= 'A') * (c <= 'M') ) THEN
|
||||
c = CHAR( ICHAR(c) + 13 )
|
||||
ELSEIF( (c >= 'n') * (c <= 'z') + (c >= 'N') * (c <= 'Z') ) THEN
|
||||
c = CHAR( ICHAR(c) - 13 )
|
||||
ENDIF
|
||||
|
||||
cod(i) = c
|
||||
ENDDO
|
||||
|
||||
WRITE(ClipBoard, Name) txt, cod ! txt=abc? XYZ!; cod=nop? KLM!;
|
||||
END
|
||||
14
Task/Rot-13/Icon/rot-13.icon
Normal file
14
Task/Rot-13/Icon/rot-13.icon
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
procedure main(arglist)
|
||||
file := open(arglist[1],"r") | &input
|
||||
every write(rot13(|read(file)))
|
||||
end
|
||||
|
||||
procedure rot13(s) #: returns rot13(string)
|
||||
static a,n
|
||||
initial {
|
||||
a := &lcase || &ucase
|
||||
(&lcase || &lcase) ? n := ( move(13), move(*&lcase) )
|
||||
(&ucase || &ucase) ? n ||:= ( move(13), move(*&ucase) )
|
||||
}
|
||||
return map(s,a,n)
|
||||
end
|
||||
1
Task/Rot-13/J/rot-13.j
Normal file
1
Task/Rot-13/J/rot-13.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
rot13=: {&((65 97+/~i.2 13) |.@[} i.256)&.(a.&i.)
|
||||
49
Task/Rot-13/Java/rot-13.java
Normal file
49
Task/Rot-13/Java/rot-13.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import java.io.*;
|
||||
|
||||
public class Rot13 {
|
||||
public static void main(String[] args) {
|
||||
BufferedReader in;
|
||||
if (args.length >= 1) {
|
||||
for (String file : args) {
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
System.out.println(convert(line));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
in = new BufferedReader(new InputStreamReader(System.in));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
System.out.println(convert(line));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String convert(String msg) {
|
||||
StringBuilder retVal = new StringBuilder();
|
||||
for (char a : msg.toCharArray()) {
|
||||
if (a >= 'A' && a <= 'Z') {
|
||||
a += 13;
|
||||
if (a > 'Z') {
|
||||
a -= 26;
|
||||
}
|
||||
} else if (a >= 'a' && a <= 'z') {
|
||||
a += 13;
|
||||
if (a > 'z') {
|
||||
a -= 26;
|
||||
}
|
||||
}
|
||||
retVal.append(a);
|
||||
}
|
||||
return retVal.toString();
|
||||
}
|
||||
}
|
||||
6
Task/Rot-13/JavaScript/rot-13.js
Normal file
6
Task/Rot-13/JavaScript/rot-13.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
function rot13(c) {
|
||||
return c.replace(/([a-m])|([n-z])/ig, function($0,$1,$2) {
|
||||
return String.fromCharCode($1 ? $1.charCodeAt(0) + 13 : $2 ? $2.charCodeAt(0) - 13 : 0) || $0;
|
||||
});
|
||||
}
|
||||
rot13("ABJURER nowhere") // NOWHERE abjurer
|
||||
4
Task/Rot-13/K/rot-13.k
Normal file
4
Task/Rot-13/K/rot-13.k
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
rot13: {a:+65 97+\:2 13#!26;_ci@[!256;a;:;|a]_ic x}
|
||||
|
||||
rot13 "Testing! 1 2 3"
|
||||
"Grfgvat! 1 2 3"
|
||||
29
Task/Rot-13/Liberty-BASIC/rot-13-1.liberty
Normal file
29
Task/Rot-13/Liberty-BASIC/rot-13-1.liberty
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
input "Type some text to be encoded, then ENTER. ";tx$
|
||||
|
||||
tex$ = Rot13$(tx$)
|
||||
print tex$
|
||||
'check
|
||||
print Rot13$(tex$)
|
||||
|
||||
wait
|
||||
|
||||
Function Rot13$(t$)
|
||||
if t$="" then
|
||||
Rot13$=""
|
||||
exit function
|
||||
end if
|
||||
for i = 1 to len(t$)
|
||||
c$=mid$(t$,i,1)
|
||||
ch$=c$
|
||||
if (asc(c$)>=asc("A")) and (asc(c$)<=asc("Z")) then
|
||||
ch$=chr$(asc(c$)+13)
|
||||
if (asc(ch$)>asc("Z")) then ch$=chr$(asc(ch$)-26)
|
||||
end if
|
||||
if (asc(c$)>=asc("a")) and (asc(c$)<=asc("z")) then
|
||||
ch$=chr$(asc(c$)+13)
|
||||
if (asc(ch$)>asc("z")) then ch$=chr$(asc(ch$)-26)
|
||||
end if
|
||||
rot$=rot$+ch$
|
||||
next
|
||||
Rot13$=rot$
|
||||
end function
|
||||
12
Task/Rot-13/Liberty-BASIC/rot-13-2.liberty
Normal file
12
Task/Rot-13/Liberty-BASIC/rot-13-2.liberty
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
Function Rot13$(t$)
|
||||
for i = 1 to len(t$)
|
||||
ch$=mid$(t$,i,1)
|
||||
if (asc(ch$)>=asc("A")) and (asc(ch$)<=asc("Z")) then
|
||||
ch$=chr$(asc("A")+ (asc(ch$)-asc("A")+13) mod 26)
|
||||
end if
|
||||
if (asc(ch$)>=asc("a")) and (asc(ch$)<=asc("z")) then
|
||||
ch$=chr$(asc("a")+ (asc(ch$)-asc("a")+13) mod 26)
|
||||
end if
|
||||
Rot13$=Rot13$+ch$
|
||||
next
|
||||
end function
|
||||
14
Task/Rot-13/Locomotive-Basic/rot-13.locomotive
Normal file
14
Task/Rot-13/Locomotive-Basic/rot-13.locomotive
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
10 INPUT "Enter a string: ",a$
|
||||
20 GOSUB 50
|
||||
30 PRINT b$
|
||||
40 END
|
||||
50 FOR i=1 TO LEN(a$)
|
||||
60 n=ASC(MID$(a$,i,1))
|
||||
70 e=255
|
||||
80 IF n>64 AND n<91 THEN e=90 ' uppercase
|
||||
90 IF n>96 AND n<123 THEN e=122 ' lowercase
|
||||
100 IF e<255 THEN n=n+13
|
||||
110 IF n>e THEN n=n-26
|
||||
120 b$=b$+CHR$(n)
|
||||
130 NEXT
|
||||
140 RETURN
|
||||
9
Task/Rot-13/Logo/rot-13.logo
Normal file
9
Task/Rot-13/Logo/rot-13.logo
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
to rot13 :c
|
||||
make "a difference ascii lowercase :c ascii "a
|
||||
if or :a < 0 :a > 25 [output :c]
|
||||
make "delta ifelse :a < 13 [13] [-13]
|
||||
output char sum :delta ascii :c
|
||||
end
|
||||
|
||||
print map "rot13 "|abjurer NOWHERE|
|
||||
nowhere ABJURER
|
||||
5
Task/Rot-13/Lua/rot-13.lua
Normal file
5
Task/Rot-13/Lua/rot-13.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
function rot(l, o) return (l < 26 and l > -1) and string.char((l+13)%26 + o) end
|
||||
a, A = string.byte'a', string.byte'A'
|
||||
val = io.read()
|
||||
val = val:gsub("(.)", function(l) return rot(l:byte()-a,a) or rot(l:byte()-A,A) or l end)
|
||||
print(val)
|
||||
19
Task/Rot-13/MATLAB/rot-13-1.m
Normal file
19
Task/Rot-13/MATLAB/rot-13-1.m
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
function r=rot13(s)
|
||||
if ischar(s)
|
||||
r=s; % preallocation and copy of non-letters
|
||||
for i=1:size(s,1)
|
||||
for j=1:size(s,2)
|
||||
if isletter(s(i,j))
|
||||
if s(i,j)>=97 % lower case
|
||||
base = 97;
|
||||
else % upper case
|
||||
base = 65;
|
||||
end
|
||||
r(i,j)=char(mod(s(i,j)-base+13,26)+base);
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
error('Argument must be a CHAR')
|
||||
end
|
||||
end
|
||||
5
Task/Rot-13/MATLAB/rot-13-2.m
Normal file
5
Task/Rot-13/MATLAB/rot-13-2.m
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
>> rot13('Hello World!')
|
||||
|
||||
ans =
|
||||
|
||||
Uryyb Jbeyq!
|
||||
13
Task/Rot-13/MATLAB/rot-13-3.m
Normal file
13
Task/Rot-13/MATLAB/rot-13-3.m
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
function text = rot13(text)
|
||||
if ischar(text)
|
||||
|
||||
selectedLetters = ( (text >= 'A') & (text <= 'Z') ); %Select upper case letters
|
||||
text(selectedLetters) = char( mod( text(selectedLetters)-'A'+13,26 )+'A' );
|
||||
|
||||
selectedLetters = ( (text >= 'a') & (text <= 'z') ); %Select lower case letters
|
||||
text(selectedLetters) = char( mod( text(selectedLetters)-'a'+13,26 )+'a' );
|
||||
|
||||
else
|
||||
error('Argument must be a string.')
|
||||
end
|
||||
end
|
||||
11
Task/Rot-13/MATLAB/rot-13-4.m
Normal file
11
Task/Rot-13/MATLAB/rot-13-4.m
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
>> plainText = char((64:123))
|
||||
|
||||
plainText =
|
||||
|
||||
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{
|
||||
|
||||
>> rot13(plainText)
|
||||
|
||||
ans =
|
||||
|
||||
@NOPQRSTUVWXYZABCDEFGHIJKLM[\]^_`nopqrstuvwxyzabcdefghijklm{
|
||||
35
Task/Rot-13/MMIX/rot-13.mmix
Normal file
35
Task/Rot-13/MMIX/rot-13.mmix
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// main registers
|
||||
p IS $255 % text pointer
|
||||
c GREG % char
|
||||
cc GREG % uppercase copy of c
|
||||
u GREG % all purpose
|
||||
|
||||
LOC Data_Segment
|
||||
GREG @
|
||||
Test BYTE "dit is een bericht voor de keizer",#a,0
|
||||
|
||||
LOC #100
|
||||
Main LDA p,Test
|
||||
TRAP 0,Fputs,StdOut % show text to encrypt
|
||||
LDA p,Test % points to text to encrypt
|
||||
JMP 4F
|
||||
// do in place text encryption
|
||||
% REPEAT
|
||||
2H ADD cc,c,0 % copy char
|
||||
SUB cc,cc,' ' % make uppercase
|
||||
CMP u,cc,'A'
|
||||
BN u,3F % IF c < 'A' OR c > 'Z' THEN next char
|
||||
CMP u,cc,'Z'
|
||||
BP u,3F
|
||||
CMP u,cc,'N' % ELSE
|
||||
BN u,1F % IF c < 'N' THEN encrypt 'up'
|
||||
SUB c,c,26 % ELSE char ready for encrypt 'down'
|
||||
1H INCL c,13 % encrypt char
|
||||
STBU c,p % replace char with encrypted char
|
||||
3H INCL p,1 % move to next char
|
||||
4H LDBU c,p % get next char
|
||||
PBNZ c,2B % UNTIL EOT
|
||||
// print result
|
||||
LDA p,Test
|
||||
TRAP 0,Fputs,StdOut % show encrypted text
|
||||
TRAP 0,Halt,0
|
||||
9
Task/Rot-13/MUMPS/rot-13.mumps
Normal file
9
Task/Rot-13/MUMPS/rot-13.mumps
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
Rot13(in) New low,rot,up
|
||||
Set up="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
Set low="abcdefghijklmnopqrstuvwxyz"
|
||||
Set rot=$Extract(up,14,26)_$Extract(up,1,13)
|
||||
Set rot=rot_$Extract(low,14,26)_$Extract(low,1,13)
|
||||
Quit $Translate(in,up_low,rot)
|
||||
|
||||
Write $$Rot13("Hello World!") ; Uryyb Jbeyq!
|
||||
Write $$Rot13("ABCDEFGHIJKLMNOPQRSTUVWXYZ") ; NOPQRSTUVWXYZABCDEFGHIJKLM
|
||||
2
Task/Rot-13/Maple/rot-13.maple
Normal file
2
Task/Rot-13/Maple/rot-13.maple
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> StringTools:-Encode( "The Quick Brown Fox Jumped Over The Lazy Dog!", encoding = rot13 );
|
||||
"Gur Dhvpx Oebja Sbk Whzcrq Bire Gur Ynml Qbt!"
|
||||
6
Task/Rot-13/Mathematica/rot-13.math
Normal file
6
Task/Rot-13/Mathematica/rot-13.math
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
ruleslower=Thread[#-> RotateLeft[#, 13]]&[CharacterRange["a", "z"]];
|
||||
rulesupper=Thread[#-> RotateLeft[#, 13]]&[CharacterRange["A", "Z"]];
|
||||
rules=Join[ruleslower,rulesupper];
|
||||
text="Hello World! Are you there!?"
|
||||
text=StringReplace[text,rules]
|
||||
text=StringReplace[text,rules]
|
||||
19
Task/Rot-13/Maxima/rot-13.maxima
Normal file
19
Task/Rot-13/Maxima/rot-13.maxima
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
rot13(a) := simplode(map(ascii, map(lambda([n],
|
||||
if (n >= 65 and n <= 77) or (n >= 97 and n <= 109) then n + 13
|
||||
elseif (n >= 78 and n <= 90) or (n >= 110 and n <= 122) then n - 13
|
||||
else n), map(cint, sexplode(a)))))$
|
||||
|
||||
lowercase: "abcdefghijklmnopqrstuvwxyz"$
|
||||
uppercase: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"$
|
||||
|
||||
rot13(lowercase);
|
||||
"nopqrstuvwxyzabcdefghijklm"
|
||||
|
||||
rot13(uppercase);
|
||||
"NOPQRSTUVWXYZABCDEFGHIJKLM"
|
||||
|
||||
rot13("The quick brown fox jumps over the lazy dog");
|
||||
"Gur dhvpx oebja sbk whzcf bire gur ynml qbt"
|
||||
|
||||
rot13(%);
|
||||
"The quick brown fox jumps over the lazy dog"
|
||||
18
Task/Rot-13/Mirah/rot-13.mirah
Normal file
18
Task/Rot-13/Mirah/rot-13.mirah
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
def rot13 (value:string)
|
||||
result = ""
|
||||
d = ' '.toCharArray[0]
|
||||
value.toCharArray.each do |c|
|
||||
testChar = Character.toLowerCase(c)
|
||||
if testChar <= 'm'.toCharArray[0] && testChar >= 'a'.toCharArray[0] then
|
||||
d = char(c + 13)
|
||||
end
|
||||
if testChar <= 'z'.toCharArray[0] && testChar >= 'n'.toCharArray[0] then
|
||||
d = char(c - 13)
|
||||
end
|
||||
result += d
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
|
||||
puts rot13("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
19
Task/Rot-13/Modula-3/rot-13.mod3
Normal file
19
Task/Rot-13/Modula-3/rot-13.mod3
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
MODULE Rot13 EXPORTS Main;
|
||||
|
||||
IMPORT Stdio, Rd, Wr;
|
||||
|
||||
VAR c: CHAR;
|
||||
|
||||
<*FATAL ANY*>
|
||||
|
||||
BEGIN
|
||||
WHILE NOT Rd.EOF(Stdio.stdin) DO
|
||||
c := Rd.GetChar(Stdio.stdin);
|
||||
IF c >= 'A' AND c <= 'M' OR c >= 'a' AND c <= 'm' THEN
|
||||
c := VAL(ORD((ORD(c) + 13)), CHAR);
|
||||
ELSIF c >= 'N' AND c <= 'Z' OR c >= 'n' AND c <= 'z' THEN
|
||||
c := VAL(ORD((ORD(c) - 13)), CHAR);
|
||||
END;
|
||||
Wr.PutChar(Stdio.stdout, c);
|
||||
END;
|
||||
END Rot13.
|
||||
94
Task/Rot-13/NetRexx/rot-13.netrexx
Normal file
94
Task/Rot-13/NetRexx/rot-13.netrexx
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref savelog symbols nobinary
|
||||
|
||||
parse arg fileNames
|
||||
|
||||
rdr = BufferedReader
|
||||
|
||||
do
|
||||
if fileNames.length > 0 then do
|
||||
loop n_ = 1 for fileNames.words
|
||||
fileName = fileNames.word(n_)
|
||||
rdr = BufferedReader(FileReader(File(fileName)))
|
||||
encipher(rdr)
|
||||
end n_
|
||||
end
|
||||
else do
|
||||
rdr = BufferedReader(InputStreamReader(System.in))
|
||||
encipher(rdr)
|
||||
end
|
||||
catch ex = IOException
|
||||
ex.printStackTrace
|
||||
end
|
||||
|
||||
return
|
||||
|
||||
method encipher(rdr = BufferedReader) public static signals IOException
|
||||
|
||||
loop label l_ forever
|
||||
line = rdr.readLine
|
||||
if line = null then leave l_
|
||||
say rot13(line)
|
||||
end l_
|
||||
return
|
||||
|
||||
method rot13(input) public static signals IllegalArgumentException
|
||||
|
||||
return caesar(input, 13, isFalse)
|
||||
|
||||
method caesar(input = Rexx, idx = int, caps = boolean) public static signals IllegalArgumentException
|
||||
|
||||
if idx < 1 | idx > 25 then signal IllegalArgumentException()
|
||||
|
||||
-- 12345678901234567890123456
|
||||
itab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
shift = itab.length - idx
|
||||
parse itab tl +(shift) tr
|
||||
otab = tr || tl
|
||||
|
||||
if caps then input = input.upper
|
||||
|
||||
cipher = input.translate(itab || itab.lower, otab || otab.lower)
|
||||
|
||||
return cipher
|
||||
|
||||
method caesar_encipher(input = Rexx, idx = int, caps = boolean) public static signals IllegalArgumentException
|
||||
|
||||
return caesar(input, idx, caps)
|
||||
|
||||
method caesar_decipher(input = Rexx, idx = int, caps = boolean) public static signals IllegalArgumentException
|
||||
|
||||
return caesar(input, int(26) - idx, isFalse)
|
||||
|
||||
method caesar_encipher(input = Rexx, idx = int) public static signals IllegalArgumentException
|
||||
|
||||
return caesar(input, idx, isFalse)
|
||||
|
||||
method caesar_decipher(input = Rexx, idx = int) public static signals IllegalArgumentException
|
||||
|
||||
return caesar(input, int(26) - idx, isFalse)
|
||||
|
||||
method caesar_encipher(input = Rexx, idx = int, opt = Rexx) public static signals IllegalArgumentException
|
||||
|
||||
return caesar(input, idx, opt)
|
||||
|
||||
method caesar_decipher(input = Rexx, idx = int, opt = Rexx) public static signals IllegalArgumentException
|
||||
|
||||
return caesar(input, int(26) - idx, opt)
|
||||
|
||||
method caesar(input = Rexx, idx = int, opt = Rexx) public static signals IllegalArgumentException
|
||||
|
||||
if opt.upper.abbrev('U') >= 1 then caps = isTrue
|
||||
else caps = isFalse
|
||||
|
||||
return caesar(input, idx, caps)
|
||||
|
||||
method caesar(input = Rexx, idx = int) public static signals IllegalArgumentException
|
||||
|
||||
return caesar(input, idx, isFalse)
|
||||
|
||||
method isTrue public static returns boolean
|
||||
return (1 == 1)
|
||||
|
||||
method isFalse public static returns boolean
|
||||
return \isTrue
|
||||
4
Task/Rot-13/OCaml/rot-13-1.ocaml
Normal file
4
Task/Rot-13/OCaml/rot-13-1.ocaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
let rot13 c = match c with
|
||||
| 'A'..'M' | 'a'..'m' -> char_of_int (int_of_char c + 13)
|
||||
| 'N'..'Z' | 'n'..'z' -> char_of_int (int_of_char c - 13)
|
||||
| _ -> c
|
||||
11
Task/Rot-13/OCaml/rot-13-2.ocaml
Normal file
11
Task/Rot-13/OCaml/rot-13-2.ocaml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
let rot13_str s =
|
||||
let len = String.length s in
|
||||
let result = String.create len in
|
||||
for i = 0 to len - 1 do
|
||||
result.[i] <- rot13 s.[i]
|
||||
done;
|
||||
result
|
||||
|
||||
(* or in OCaml 4.00+:
|
||||
let rot13_str = String.map rot13
|
||||
*)
|
||||
5
Task/Rot-13/OCaml/rot-13-3.ocaml
Normal file
5
Task/Rot-13/OCaml/rot-13-3.ocaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
let () =
|
||||
try while true do
|
||||
String.iter (fun c -> print_char (rot13 c)) (read_line());
|
||||
print_newline()
|
||||
done with End_of_file -> ()
|
||||
25
Task/Rot-13/Objeck/rot-13.objeck
Normal file
25
Task/Rot-13/Objeck/rot-13.objeck
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
bundle Default {
|
||||
class Rot13 {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
Rot13("nowhere ABJURER")->PrintLine();
|
||||
}
|
||||
|
||||
function : native : Rot13(text : String) ~ String {
|
||||
rot := "";
|
||||
each(i : text) {
|
||||
c := text->Get(i);
|
||||
if(c >= 'a' & c <= 'm' | c >= 'A' & c <= 'M') {
|
||||
rot->Append(c + 13);
|
||||
}
|
||||
else if(c >= 'n' & c <= 'z' | c >= 'N' & c <= 'Z') {
|
||||
rot->Append(c - 13);
|
||||
}
|
||||
else {
|
||||
rot->Append(c);
|
||||
};
|
||||
};
|
||||
|
||||
return rot;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Task/Rot-13/Oz/rot-13.oz
Normal file
14
Task/Rot-13/Oz/rot-13.oz
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
declare
|
||||
fun {RotChar C}
|
||||
if C >= &A andthen C =< &Z then &A + (C - &A + 13) mod 26
|
||||
elseif C >= &a andthen C =< &z then &a + (C - &a + 13) mod 26
|
||||
else C
|
||||
end
|
||||
end
|
||||
|
||||
fun {Rot13 S}
|
||||
{Map S RotChar}
|
||||
end
|
||||
in
|
||||
{System.showInfo {Rot13 "NOWHERE Abjurer 42"}}
|
||||
{System.showInfo {Rot13 {Rot13 "NOWHERE Abjurer 42"}}}
|
||||
7
Task/Rot-13/PARI-GP/rot-13.pari
Normal file
7
Task/Rot-13/PARI-GP/rot-13.pari
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
rot13(s)={
|
||||
s=Vecsmall(s);
|
||||
for(i=1,#s,
|
||||
if(s[i]>109&s[i]<123,s[i]-=13,if(s[i]<110&s[i]>96,s[i]+=13,if(s[i]>77&s[i]<91,s[i]-=13,if(s[i]<78&s[i]>64,s[i]+=13))))
|
||||
);
|
||||
Strchr(s)
|
||||
};
|
||||
1
Task/Rot-13/PHP/rot-13-1.php
Normal file
1
Task/Rot-13/PHP/rot-13-1.php
Normal file
|
|
@ -0,0 +1 @@
|
|||
echo str_rot13('foo'), "\n";
|
||||
8
Task/Rot-13/PHP/rot-13-2.php
Normal file
8
Task/Rot-13/PHP/rot-13-2.php
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
function rot13($s) {
|
||||
return strtr($s, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
|
||||
'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm');
|
||||
}
|
||||
|
||||
echo rot13('foo'), "\n";
|
||||
?>
|
||||
17
Task/Rot-13/PL-I/rot-13.pli
Normal file
17
Task/Rot-13/PL-I/rot-13.pli
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
rotate: procedure (in) options (main); /* 2 March 2011 */
|
||||
declare in character (100) varying;
|
||||
declare line character (500) varying;
|
||||
declare input file;
|
||||
|
||||
open file (input) title ('/' || in || ',type(text),recsize(500)' );
|
||||
|
||||
on endfile (input) stop;
|
||||
|
||||
do forever;
|
||||
get file (input) edit (line) (L);
|
||||
line = translate (
|
||||
line, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
|
||||
'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm');
|
||||
put edit (line) (a); put skip;
|
||||
end;
|
||||
end;
|
||||
29
Task/Rot-13/Pascal/rot-13.pascal
Normal file
29
Task/Rot-13/Pascal/rot-13.pascal
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
program rot13(input, output);
|
||||
|
||||
function rot13(someText: string): string;
|
||||
var
|
||||
i: integer;
|
||||
ch: char;
|
||||
resultText: string = '';
|
||||
|
||||
begin
|
||||
for i := 1 to Length(someText) do begin
|
||||
ch := someText[i];
|
||||
case ch of
|
||||
'A' .. 'M', 'a' .. 'm': ch := chr(ord(ch)+13);
|
||||
'N' .. 'Z', 'n' .. 'z': ch := chr(ord(ch)-13)
|
||||
end;
|
||||
resultText := resultText + ch
|
||||
end;
|
||||
rot13 := resultText
|
||||
end;
|
||||
|
||||
var
|
||||
line: string;
|
||||
|
||||
begin
|
||||
while not eof(input) do begin
|
||||
readln(line);
|
||||
writeln(rot13(line))
|
||||
end
|
||||
end.
|
||||
4
Task/Rot-13/Perl-6/rot-13.pl6
Normal file
4
Task/Rot-13/Perl-6/rot-13.pl6
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
sub rot13 { $^s.trans: 'A..Za..z' => 'N..ZA..Mn..za..m' }
|
||||
|
||||
multi MAIN () { print rot13 slurp }
|
||||
multi MAIN (*@files) { print rot13 [~] map &slurp, @files }
|
||||
7
Task/Rot-13/Perl/rot-13-1.pl
Normal file
7
Task/Rot-13/Perl/rot-13-1.pl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
sub rot13 {
|
||||
my $string = shift;
|
||||
$string =~ tr/A-Za-z/N-ZA-Mn-za-m/;
|
||||
return $string;
|
||||
}
|
||||
|
||||
print rot13($_) while (<>);
|
||||
1
Task/Rot-13/Perl/rot-13-2.pl
Normal file
1
Task/Rot-13/Perl/rot-13-2.pl
Normal file
|
|
@ -0,0 +1 @@
|
|||
perl -pe 'tr/A-Za-z/N-ZA-Mn-za-m/'
|
||||
7
Task/Rot-13/PicoLisp/rot-13-1.l
Normal file
7
Task/Rot-13/PicoLisp/rot-13-1.l
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(de rot13-Ch (C)
|
||||
(if
|
||||
(or
|
||||
(member C '`(apply circ (chop "ABCDEFGHIJKLMNOPQRSTUVWXYZ")))
|
||||
(member C '`(apply circ (chop "abcdefghijklmnopqrstuvwxyz"))) )
|
||||
(get @ 14)
|
||||
C ) )
|
||||
7
Task/Rot-13/PicoLisp/rot-13-2.l
Normal file
7
Task/Rot-13/PicoLisp/rot-13-2.l
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(de rot13-Ch (C)
|
||||
(cond
|
||||
((>= "M" (uppc C) "A")
|
||||
(char (+ (char C) 13)) )
|
||||
((>= "Z" (uppc C) "N")
|
||||
(char (- (char C) 13)) )
|
||||
(T C) ) )
|
||||
3
Task/Rot-13/PicoLisp/rot-13-3.l
Normal file
3
Task/Rot-13/PicoLisp/rot-13-3.l
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(de rot13-stdIn ()
|
||||
(while (line)
|
||||
(prinl (mapcar rot13-Ch @)) ) )
|
||||
6
Task/Rot-13/Pike/rot-13.pike
Normal file
6
Task/Rot-13/Pike/rot-13.pike
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import Crypto;
|
||||
|
||||
int main(){
|
||||
string r = rot13("Hello, World");
|
||||
write(r + "\n");
|
||||
}
|
||||
14
Task/Rot-13/Pop11/rot-13.pop11
Normal file
14
Task/Rot-13/Pop11/rot-13.pop11
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
define rot13(s);
|
||||
lvars j, c;
|
||||
for j from 1 to length(s) do
|
||||
s(j) -> c;
|
||||
if `A` <= c and c <= `M` or `a` <= c and c <= `m` then
|
||||
c + 13 -> s(j);
|
||||
elseif `N` <= c and c <= `Z` or `n` <= c and c <= `z` then
|
||||
c - 13 -> s(j);
|
||||
endif;
|
||||
endfor;
|
||||
s;
|
||||
enddefine;
|
||||
|
||||
rot13('NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm') =>
|
||||
10
Task/Rot-13/PostScript/rot-13.ps
Normal file
10
Task/Rot-13/PostScript/rot-13.ps
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/r13 {
|
||||
4 dict begin
|
||||
/rotc {
|
||||
{
|
||||
{{{64 gt} {91 lt}} all?} {65 - 13 + 26 mod 65 +} is?
|
||||
{{{95 gt} {123 lt}} all?} {97 - 13 + 26 mod 97 +} is?
|
||||
} cond
|
||||
}.
|
||||
{rotc} map cvstr
|
||||
end}.
|
||||
10
Task/Rot-13/PowerShell/rot-13.psh
Normal file
10
Task/Rot-13/PowerShell/rot-13.psh
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
Function ROT13($String)
|
||||
{
|
||||
$Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz "
|
||||
$Cipher = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm "
|
||||
Foreach($Char in $String.ToCharArray())
|
||||
{
|
||||
$NewString += $Cipher.Chars($Alphabet.IndexOf($Char))
|
||||
}
|
||||
Return $NewString
|
||||
}
|
||||
7
Task/Rot-13/Prolog/rot-13-1.pro
Normal file
7
Task/Rot-13/Prolog/rot-13-1.pro
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
rot13(Str, SR) :-
|
||||
maplist(rot, Str, Str1),
|
||||
string_to_list(SR, Str1).
|
||||
|
||||
rot(C, C1) :-
|
||||
( member(C, "abcdefghijklmABCDEFGHIJKLM") -> C1 is C+13;
|
||||
( member(C, "nopqrstuvwxyzNOPQRSTUVWXYZ") -> C1 is C-13; C1 = C)).
|
||||
2
Task/Rot-13/Prolog/rot-13-2.pro
Normal file
2
Task/Rot-13/Prolog/rot-13-2.pro
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
?- rot13("The Quick Brown Fox Jumped Over The Lazy Dog!", SR).
|
||||
SR = "Gur Dhvpx Oebja Sbk Whzcrq Bire Gur Ynml Qbt!".
|
||||
29
Task/Rot-13/PureBasic/rot-13.purebasic
Normal file
29
Task/Rot-13/PureBasic/rot-13.purebasic
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
Declare.s Rot13(text_to_code.s)
|
||||
|
||||
If OpenConsole()
|
||||
Define txt$
|
||||
|
||||
Print("Enter a string to encode: "): txt$=Input()
|
||||
|
||||
PrintN("Coded : "+Rot13(txt$))
|
||||
PrintN("Decoded: "+Rot13(Rot13(txt$)))
|
||||
|
||||
Print("Press ENTER to quit."): Input()
|
||||
CloseConsole()
|
||||
EndIf
|
||||
|
||||
Procedure.s Rot13(s.s)
|
||||
Protected.i i
|
||||
Protected.s t, u
|
||||
For i=1 To Len(s)
|
||||
t=Mid(s,i,1)
|
||||
Select Asc(t)
|
||||
Case Asc("a") To Asc("m"), Asc("A") To Asc("M")
|
||||
t=chr(Asc(t)+13)
|
||||
Case Asc("n") To Asc("z"), Asc("N") To Asc("Z")
|
||||
t=chr(Asc(t)-13)
|
||||
EndSelect
|
||||
u+t
|
||||
Next
|
||||
ProcedureReturn u
|
||||
EndProcedure
|
||||
21
Task/Rot-13/Python/rot-13-1.py
Normal file
21
Task/Rot-13/Python/rot-13-1.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python
|
||||
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(
|
||||
string.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__":
|
||||
"""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)!
|
||||
21
Task/Rot-13/Python/rot-13-2.py
Normal file
21
Task/Rot-13/Python/rot-13-2.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python
|
||||
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__":
|
||||
"""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="")
|
||||
10
Task/Rot-13/R/rot-13.r
Normal file
10
Task/Rot-13/R/rot-13.r
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
rot13 <- function(x)
|
||||
{
|
||||
old <- paste(letters, LETTERS, collapse="", sep="")
|
||||
new <- paste(substr(old, 27, 52), substr(old, 1, 26), sep="")
|
||||
chartr(old, new, x)
|
||||
}
|
||||
x <- "The Quick Brown Fox Jumps Over The Lazy Dog!.,:;'#~[]{}"
|
||||
rot13(x) # "Gur Dhvpx Oebja Sbk Whzcf Bire Gur Ynml Qbt!.,:;'#~[]{}"
|
||||
x2 <- paste(letters, LETTERS, collapse="", sep="")
|
||||
rot13(x2) # "nNoOpPqQrRsStTuUvVwWxXyYzZaAbBcCdDeEfFgGhHiIjJkKlLmM"
|
||||
84
Task/Rot-13/REBOL/rot-13.rebol
Normal file
84
Task/Rot-13/REBOL/rot-13.rebol
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
REBOL [
|
||||
Title: "Rot-13"
|
||||
Date: 2009-12-14
|
||||
Author: oofoe
|
||||
URL: http://rosettacode.org/wiki/Rot-13
|
||||
]
|
||||
|
||||
; Test data has upper and lower case characters as well as characters
|
||||
; that should not be transformed, like numbers, spaces and symbols.
|
||||
|
||||
text: "This is a 28-character test!"
|
||||
|
||||
print "Using cipher table:"
|
||||
|
||||
; I build a set of correspondence lists here. 'x' is the letters from
|
||||
; A-Z, in both upper and lowercase form. Note that REBOL can iterate
|
||||
; directly over the alphabetic character sequence in the for loop. 'y'
|
||||
; is the cipher form, 'x' rotated by 26 characters (remember, I have
|
||||
; the lower and uppercase forms together). 'r' holds the final result,
|
||||
; built as I iterate across the 'text' string. I search for the
|
||||
; current character in the plaintext list ('x'), if I find it, I get
|
||||
; the corresponding character from the ciphertext list
|
||||
; ('y'). Otherwise, I pass the character through untransformed, then
|
||||
; return the final string.
|
||||
|
||||
rot-13: func [
|
||||
"Encrypt or decrypt rot-13 with tables."
|
||||
text [string!] "Text to en/decrypt."
|
||||
/local x y r i c
|
||||
] [
|
||||
x: copy "" for i #"a" #"z" 1 [append x rejoin [i uppercase i]]
|
||||
y: rejoin [copy skip x 26 copy/part x 26]
|
||||
r: copy ""
|
||||
|
||||
repeat i text [append r either c: find/case x i [y/(index? c)][i]]
|
||||
r
|
||||
]
|
||||
|
||||
; Note that I am setting the 'text' variable to the result of rot-13
|
||||
; so I can reuse it again on the next call. The rot-13 algorithm is
|
||||
; reversible, so I can just run it again without modification to decrypt.
|
||||
|
||||
print [" Encrypted:" text: rot-13 text]
|
||||
print [" Decrypted:" text: rot-13 text]
|
||||
|
||||
|
||||
print "Using parse:"
|
||||
|
||||
clamp: func [
|
||||
"Contain a value within two enclosing values. Wraps if necessary."
|
||||
x v y
|
||||
][
|
||||
x: to-integer x v: to-integer v y: to-integer y
|
||||
case [v < x [y - v] v > y [v - y + x - 1] true v]
|
||||
]
|
||||
|
||||
; I'm using REBOL's 'parse' word here. I set up character sets for
|
||||
; upper and lower-case letters, then let parse walk across the
|
||||
; text. It looks for matches to upper-case letters, then lower-case,
|
||||
; then skips to the next one if it can't find either. If a matching
|
||||
; character is found, it's mathematically incremented by 13 and
|
||||
; clamped to the appropriate character range. parse changes the
|
||||
; character in place in the string, hence this is a destructive
|
||||
; operation.
|
||||
|
||||
rot-13: func [
|
||||
"Encrypt or decrypt rot-13 with parse."
|
||||
text [string!] "Text to en/decrypt. Note: Destructive!"
|
||||
] [
|
||||
u: charset [#"A" - #"Z"]
|
||||
l: charset [#"a" - #"z"]
|
||||
|
||||
parse text [some [
|
||||
i: ; Current position.
|
||||
u (i/1: to-char clamp #"A" i/1 + 13 #"Z") | ; Upper case.
|
||||
l (i/1: to-char clamp #"a" i/1 + 13 #"z") | ; Lower case.
|
||||
skip]] ; Ignore others.
|
||||
text
|
||||
]
|
||||
|
||||
; As you see, I don't need to re-assign 'text' anymore.
|
||||
|
||||
print [" Encrypted:" rot-13 text]
|
||||
print [" Decrypted:" rot-13 text]
|
||||
30
Task/Rot-13/REXX/rot-13.rexx
Normal file
30
Task/Rot-13/REXX/rot-13.rexx
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/*REXX program to encode several text strings with ROT 13 algorithm. */
|
||||
aa = 'foo'
|
||||
say 'simple text = 'aa
|
||||
say ' rot13 text = 'rot13(aa)
|
||||
say
|
||||
|
||||
bb = 'bar'
|
||||
say 'simple text = 'bb
|
||||
say ' rot13 text = 'rot13(bb)
|
||||
say
|
||||
|
||||
cc = "Noyr jnf V, 'rer V fnj Ryon."
|
||||
say 'simple text = 'cc
|
||||
say ' rot13 text = 'rot13(cc)
|
||||
say
|
||||
|
||||
dd = 'abc? ABC!'
|
||||
say 'simple text = 'dd
|
||||
say ' rot13 text = 'rot13(dd)
|
||||
say
|
||||
|
||||
ee = 'abjurer NOWHERE'
|
||||
say 'simple text = 'ee
|
||||
say ' rot13 text = 'rot13(ee)
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
|
||||
/*──────────────────────────────────ROT13 subroutine────────────────────*/
|
||||
rot13: return translate(arg(1),,
|
||||
'abcdefghijklmABCDEFGHIJKLMnopqrstuvwxyzNOPQRSTUVWXYZ',,
|
||||
'nopqrstuvwxyzNOPQRSTUVWXYZabcdefghijklmABCDEFGHIJKLM')
|
||||
17
Task/Rot-13/Racket/rot-13.rkt
Normal file
17
Task/Rot-13/Racket/rot-13.rkt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/env racket
|
||||
#lang racket/base
|
||||
|
||||
(define (run i o)
|
||||
(for ([ch (in-producer regexp-match #f #rx#"[a-zA-Z]" i 0 #f o)])
|
||||
(define b (bytes-ref (car ch) 0))
|
||||
(define a (if (< b 96) 65 97))
|
||||
(write-byte (+ (modulo (+ 13 (- b a)) 26) a))))
|
||||
|
||||
(require racket/cmdline)
|
||||
(command-line
|
||||
#:help-labels "(\"-\" specifies standard input)"
|
||||
#:args files
|
||||
(for ([f (if (null? files) '("-") files)])
|
||||
(if (equal? f "-")
|
||||
(run (current-input-port) (current-output-port))
|
||||
(call-with-input-file f ( (i) (run i (current-output-port)))))))
|
||||
11
Task/Rot-13/Retro/rot-13.retro
Normal file
11
Task/Rot-13/Retro/rot-13.retro
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{{
|
||||
: rotate ( cb-c ) tuck - 13 + 26 mod + ;
|
||||
: rotate? ( c-c )
|
||||
dup 'a 'z within [ 'a rotate ] ifTrue
|
||||
dup 'A 'Z within [ 'A rotate ] ifTrue ;
|
||||
---reveal---
|
||||
: rot13 ( s-s ) dup [ [ @ rotate? ] sip ! ] ^types'STRING each@ ;
|
||||
}}
|
||||
|
||||
"abcdef123GHIJKL" rot13 dup puts cr rot13 puts
|
||||
"abjurer NOWHERE" rot13 puts
|
||||
9
Task/Rot-13/Ruby/rot-13.rb
Normal file
9
Task/Rot-13/Ruby/rot-13.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Returns a copy of _s_ with rot13 encoding.
|
||||
def rot13(s)
|
||||
s.tr('A-Za-z', 'N-ZA-Mn-za-m')
|
||||
end
|
||||
|
||||
# Perform rot13 on files from command line, or standard input.
|
||||
while line = ARGF.gets
|
||||
print rot13(line)
|
||||
end
|
||||
14
Task/Rot-13/Run-BASIC/rot-13.run
Normal file
14
Task/Rot-13/Run-BASIC/rot-13.run
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
INPUT "Enter a string: "; s$
|
||||
ans$ = ""
|
||||
FOR a = 1 TO LEN(s$)
|
||||
letter$ = MID$(s$, a, 1)
|
||||
IF letter$ >= "A" AND letter$ <= "Z" THEN
|
||||
char$ = CHR$(ASC(letter$) + 13)
|
||||
IF char$ > "Z" THEN char$ = CHR$(ASC(char$) - 26)
|
||||
else
|
||||
if letter$ >= "a" AND letter$ <= "z" THEN char$ = CHR$(ASC(letter$) + 13)
|
||||
IF char$ > "z" THEN char$ = CHR$(ASC(char$) - 26) ELSE char$ = letter$
|
||||
END IF
|
||||
ans$ = ans$ + char$
|
||||
NEXT a
|
||||
PRINT ans$
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue