September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,7 +1,9 @@
|
|||
-- ROT 13 --------------------------------------------------------------------
|
||||
|
||||
-- rot13 :: String -> String
|
||||
on rot13(str)
|
||||
script rt13
|
||||
on lambda(x)
|
||||
on |λ|(x)
|
||||
if (x ≥ "a" and x ≤ "m") or (x ≥ "A" and x ≤ "M") then
|
||||
character id ((id of x) + 13)
|
||||
else if (x ≥ "n" and x ≤ "z") or (x ≥ "N" and x ≤ "Z") then
|
||||
|
|
@ -9,24 +11,22 @@ on rot13(str)
|
|||
else
|
||||
x
|
||||
end if
|
||||
end lambda
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
intercalate("", map(rt13, characters of str))
|
||||
end rot13
|
||||
|
||||
|
||||
-- TEST
|
||||
-- TEST ----------------------------------------------------------------------
|
||||
on run
|
||||
|
||||
rot13("nowhere ABJURER")
|
||||
|
||||
--> "abjurer NOWHERE"
|
||||
|
||||
end run
|
||||
|
||||
|
||||
-- GENERIC FUNCTIONS
|
||||
-- GENERIC FUNCTIONS ---------------------------------------------------------
|
||||
|
||||
-- map :: (a -> b) -> [a] -> [b]
|
||||
on map(f, xs)
|
||||
|
|
@ -34,7 +34,7 @@ on map(f, xs)
|
|||
set lng to length of xs
|
||||
set lst to {}
|
||||
repeat with i from 1 to lng
|
||||
set end of lst to lambda(item i of xs, i, xs)
|
||||
set end of lst to |λ|(item i of xs, i, xs)
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
|
|
@ -55,7 +55,7 @@ on mReturn(f)
|
|||
f
|
||||
else
|
||||
script
|
||||
property lambda : f
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
|
|
|||
2
Task/Rot-13/BaCon/rot-13.bacon
Normal file
2
Task/Rot-13/BaCon/rot-13.bacon
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
INPUT "String: ", s$
|
||||
PRINT "Output: ", REPLACE$(s$, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM", 2)
|
||||
47
Task/Rot-13/Batch-File/rot-13.bat
Normal file
47
Task/Rot-13/Batch-File/rot-13.bat
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
@echo off & setlocal enabledelayedexpansion
|
||||
|
||||
:: ROT13 obfuscator Michael Sanders - 2017
|
||||
::
|
||||
:: example: rot13.cmd Rire abgvpr cflpuvpf arire jva gur ybggrel?
|
||||
|
||||
:setup
|
||||
|
||||
set str=%*
|
||||
set buf=%str%
|
||||
set len=0
|
||||
|
||||
:getlength
|
||||
|
||||
if not defined buf goto :start
|
||||
set buf=%buf:~1%
|
||||
set /a len+=1
|
||||
goto :getlength
|
||||
|
||||
:start
|
||||
|
||||
if %len% leq 0 (echo rot13: zero length string & exit /b 1)
|
||||
set abc=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
|
||||
set nop=NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm
|
||||
set r13=
|
||||
set num=0
|
||||
set /a len-=1
|
||||
|
||||
:rot13
|
||||
|
||||
for /l %%x in (!num!,1,%len%) do (
|
||||
set log=0
|
||||
for /l %%y in (0,1,51) do (
|
||||
if "!str:~%%x,1!"=="!abc:~%%y,1!" (
|
||||
call set r13=!r13!!nop:~%%y,1!
|
||||
set /a num=%%x+1
|
||||
set /a log+=1
|
||||
if !num! lss %len% goto :rot13
|
||||
)
|
||||
)
|
||||
if !log!==0 call set r13=!r13!!str:~%%x,1!
|
||||
)
|
||||
|
||||
:done
|
||||
|
||||
echo !r13!
|
||||
endlocal & exit /b 0
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
#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;
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
cat filename | ./rot13
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
char rot13_char(char s);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int c;
|
||||
if (argc != 1) {
|
||||
fprintf(stderr, "Usage: %s\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
while((c = getchar()) != EOF) {
|
||||
putchar(rot13_char(c));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char rot13_char(char c) {
|
||||
if (isalpha(c)) {
|
||||
char alpha = islower(c) ? 'a' : 'A';
|
||||
return (c - alpha + 13) % 26 + alpha;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
51
Task/Rot-13/C/rot-13.c
Normal file
51
Task/Rot-13/C/rot-13.c
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static char rot13_table[UCHAR_MAX + 1];
|
||||
|
||||
static void init_rot13_table(void) {
|
||||
static const unsigned char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
static const unsigned char lower[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
for (int ch = '\0'; ch <= UCHAR_MAX; ch++) {
|
||||
rot13_table[ch] = ch;
|
||||
}
|
||||
for (const unsigned char *p = upper; p[13] != '\0'; p++) {
|
||||
rot13_table[p[0]] = p[13];
|
||||
rot13_table[p[13]] = p[0];
|
||||
}
|
||||
for (const unsigned char *p = lower; p[13] != '\0'; p++) {
|
||||
rot13_table[p[0]] = p[13];
|
||||
rot13_table[p[13]] = p[0];
|
||||
}
|
||||
}
|
||||
|
||||
static void rot13_file(FILE *fp)
|
||||
{
|
||||
int ch;
|
||||
while ((ch = fgetc(fp)) != EOF) {
|
||||
fputc(rot13_table[ch], stdout);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
init_rot13_table();
|
||||
|
||||
if (argc > 1) {
|
||||
for (int i = 1; i < argc; i++) {
|
||||
FILE *fp = fopen(argv[i], "r");
|
||||
if (fp == NULL) {
|
||||
perror(argv[i]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
rot13_file(fp);
|
||||
fclose(fp);
|
||||
}
|
||||
} else {
|
||||
rot13_file(stdin);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
(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"
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
(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!"
|
||||
|
|
@ -1,7 +1,14 @@
|
|||
import Data.Char
|
||||
import Data.Char (isAlpha, toLower, chr, ord)
|
||||
|
||||
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)
|
||||
| isAlpha c = chr (if_ (toLower c <= 'm') (+) (-) (ord c) 13)
|
||||
| otherwise = c
|
||||
|
||||
if_ :: Bool -> a -> a -> a
|
||||
if_ True x _ = x
|
||||
if_ False _ y = y
|
||||
|
||||
-- Simple test
|
||||
main :: IO ()
|
||||
main = print $ rot13 <$> "Abjurer nowhere"
|
||||
|
|
|
|||
|
|
@ -1,49 +1,33 @@
|
|||
import java.io.*;
|
||||
|
||||
public class Rot13 {
|
||||
public static void main(String[] args) {
|
||||
BufferedReader in;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
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();
|
||||
try (InputStream in = new BufferedInputStream(new FileInputStream(file))) {
|
||||
rot13(in, System.out);
|
||||
}
|
||||
}
|
||||
} 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();
|
||||
}
|
||||
rot13(System.in, System.out);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
private static void rot13(InputStream in, OutputStream out) throws IOException {
|
||||
int ch;
|
||||
while ((ch = in.read()) != -1) {
|
||||
out.write(rot13((char) ch));
|
||||
}
|
||||
return retVal.toString();
|
||||
}
|
||||
|
||||
private static char rot13(char ch) {
|
||||
if (ch >= 'A' && ch <= 'Z') {
|
||||
return (char) (((ch - 'A') + 13) % 26 + 'A');
|
||||
}
|
||||
if (ch >= 'a' && ch <= 'z') {
|
||||
return (char) (((ch - 'a') + 13) % 26 + 'a');
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
/*REXX program encodes several example text strings using the ROT-13 algorithm. */
|
||||
@simple = 'simple text ='
|
||||
@rot_13 = 'rot-13 text ='
|
||||
|
||||
$= 'foo' ; say @simple $; say @rot_13 rot13($); say
|
||||
$= 'bar' ; say @simple $; say @rot_13 rot13($); say
|
||||
$= "Noyr jnf V, 'rer V fnj Ryon." ; say @simple $; say @rot_13 rot13($); say
|
||||
$= 'abc? ABC!' ; say @simple $; say @rot_13 rot13($); say
|
||||
$= 'abjurer NOWHERE' ; say @simple $; say @rot_13 rot13($); say
|
||||
|
||||
$='foo' ; say "simple text=" $; say 'rot-13 text=' rot13($); say
|
||||
$='bar' ; say "simple text=" $; say 'rot-13 text=' rot13($); say
|
||||
$="Noyr jnf V, 'rer V fnj Ryon."; say "simple text=" $; say 'rot-13 text=' rot13($); say
|
||||
$='abc? ABC!' ; say "simple text=" $; say 'rot-13 text=' rot13($); say
|
||||
$='abjurer NOWHERE' ; say "simple text=" $; say 'rot-13 text=' rot13($); say
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
rot13: return translate( arg(1), 'abcdefghijklmABCDEFGHIJKLMnopqrstuvwxyzNOPQRSTUVWXYZ',,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/env racket
|
||||
#!/usr/bin/env racket
|
||||
#lang racket/base
|
||||
|
||||
(define (run i o)
|
||||
|
|
|
|||
2
Task/Rot-13/Sed/rot-13.sed
Normal file
2
Task/Rot-13/Sed/rot-13.sed
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
y/abcdefghijklmnopqrstuvwxyz/nopqrstuvwxyzabcdefghijklm/
|
||||
y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/NOPQRSTUVWXYZABCDEFGHIJKLM/
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
fun rot13char c =
|
||||
if c >= #"a" andalso c <= #"m" orelse c >= #"A" andalso c <= #"M" then
|
||||
chr (ord c + 13)
|
||||
else if c >= #"n" andalso c <= #"z" orelse c >= #"N" andalso c <= #"Z" then
|
||||
chr (ord c - 13)
|
||||
else
|
||||
c
|
||||
|
||||
val rot13 = String.map rot13char
|
||||
8
Task/Rot-13/Zkl/rot-13.zkl
Normal file
8
Task/Rot-13/Zkl/rot-13.zkl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#!/home/craigd/Bin/zkl
|
||||
fcn rot13(text){
|
||||
text.translate("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
"nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM");
|
||||
}
|
||||
text:=(vm.arglist or File.stdin); // command line or pipe
|
||||
text.pump(File.stdout,rot13); // rotate each word and print it
|
||||
if(text.isType(List)) File.stdout.writeln(); // command line gets ending newline
|
||||
Loading…
Add table
Add a link
Reference in a new issue