9afbd1 No.4025
Rot13 thread!
key = 13
U = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
L = 'abcdefghijklmnopqrstuvwxyz'
rot13 = str.maketrans(U + L, U[key:] + U[:key] + L[key:] + L[:key])
print('rot13 is cool!'.translate(rot13))
____________________________
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4027
type 256 ohssre: gnoyr
: genafyngr ( p -- p' ) gnoyr + p@ ;
mnexre renfr
: genafyngr! ( p p' -- ) fjnc gnoyr + p! ;
: vqragvgl ( n-gnoyr -- ) 256 0 qb v qhc genafyngr! ybbc ;
: ebg13-gnoyr ( n-gnoyr -- )
[ pune z ] yvgreny [pune] a qb v qhc 13 - genafyngr! ybbc
[ pune Z ] yvgreny [pune] A qb v qhc 13 - genafyngr! ybbc
[ pune m ] yvgreny [pune] n qb v qhc 13 + genafyngr! ybbc
[ pune M ] yvgreny [pune] N qb v qhc 13 + genafyngr! ybbc ;
vqragvgl
ebg13-gnoyr
renfr
: ebg13 ( 'fgevat' -- )
obhaqf qb v p@ genafyngr v p! ybbc ;
fbhepr 2qhc ebg13 type
A pretend-generic solution. You could make any kind of ASCII translation with that table, or write a "maketrans" that maps one string's characters to another, or a "rotate" that maps characters to a rotation of themselves.
But since you only want rot13 it's a lot of wasted code. Not Forthy. Which is why it's erased from the dictionary after use. That way, if an executable is built, it'll just have the translation table as set up for rot13, and none of the code that set it up.
The last line prints itself out, rot13'd. 'glcr' is the rot13 of 'type', the Forth word that prints a string. Yes, the source code is modified so that 'glcr' becomes 'type' before Forth looks at it to run it.
Source is copyright protected and is encrypted. Breaking encryption is a violation of the DMCA and FBI FBI FBI fucko
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4039
>>4025
>>4027
read a book, rot13 is trivial.
#include <bits/stdc++.h>
using namespace std;
int main() {
string l;
while(getline(cin, l)) {
for(int i = 0; i < l.size(); ++i) {
if(isalpha(l[i])) {
cout << (char)(((tolower(l[i]) - 'a') + 13)%26 + (islower(l[i]) ? 'a' : 'A'));
} else {
cout << l[i];
}
}
cout << '\n';
}
return 0;
}
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4041
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4044
>rot13
>an accomplishment
int rot13(char **original) {
for(int i = 0; i < strlen(original); i++) {
if(*original[i] >= 65 && *original[i] <= 90) {
*original[i] = (*original[i] - 52) % 26 + 65
} else if(*original[i] >= 90 && *original[i] <= 122) {
*original[i] = (*original[i] - 77) % 26 + 90
}
}
return 0
}
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4047
>>4044
It's just a bit of fun.
var rot13 = {
alpha: "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz",
key: 13,
translateChar: function(ch) {
return !ch.match(/[A-Z]/i) ? ch :
this.alpha[(this.alpha.indexOf(ch) + this.key * 2) % this.alpha.length];
},
translate: function(text) {
var result = [];
for (var i in text) {
result.push(this.translateChar(text[i]));
}
return result.join("");
}
};
alert(rot13.translate("Rot13 is cool!"));
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4064
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4072
>>4025
Code golf so far in Python2 -
a = "abcdefghijklmnopqrstuvwxyz"
b = a[13:]+a[:13]
z = {x:y for x,y in map(None,a+" ",b+" ")}
print ''.join([z[c] for c in raw_input('>').lower()])
I'm trying to find some way to print z[c] or c if z[c] isn't set, but I can't do that with a simple z[c]or c, so I just tossed some spaces onto the end of each string.
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4074
Magical.
string rot13(string str)
{
transform(str.begin(),str.end(),str.begin(),
[](char c){char off = (isupper(c)?'A':'a'); return (c-off+13)%26+off;});
return str;
}
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4085
The laziest way
def rot13(s):
a = "abcdefghijklmnopqrstuvwxyzabcdefghijklm"
for c in s:
print(a[a.index(c)+13] if c != " " else c,end="")
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4086
>>4039
Yes, of course it's trivial. That's why overengineering it and optimizing is so amusing. If you just want to golf it,
tr/a-zA-Z/n-za-mN-ZA-M/
Your code has two branches per char, excluding the branch in the loop. The Forth and Perl solutions have none (on ASCII). It's also easy to do without the table as well, for no branches and no memory accesses apart from the operation of the loop itself.
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4087
>>4085
Jesus Christ that's horrifying.
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4120
"".join(chr((12+ord(x)%32)%26+65+(x>"Z")*32) if x.isalpha() else x for x in s)
I think that would do the trick.
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4126
>>4085
>actually repeating the string 13 more characters to not read out of index
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4127
#Rot13
alphabet = 'abcdefghijklmnopqrstuvwxyz'
key = 13
def rot(string,key):
out = ''
for i in string:
if (i.lower() in alphabet):
c = alphabet[(alphabet.index(i.lower())+key)%len(alphabet)]
out += (c.upper() if i.isupper() else c)
else:
out += i
return out
print(rot("I suck at programming.",key))
V fhpx ng cebtenzzvat.
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4128
>>4085
Fucking terrible. It can't even use capital letters.
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4161
#!/bin/sh
tr a-zA-Z n-za-mN-ZA-M $*
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4175
A bit overkill but it was fun.
function makeTrans(inTable, outTable) {
if (inTable.length != outTable.length) {
throw new Error("makeTrans: inTable and outTable are different lengths.");
}
var dict = Object.create(null);
for (var i in inTable) {
dict[inTable[i]] = outTable[i];
}
var translate = function(text) {
var result = [];
for (var i in text) {
var ch = text[i];
if (ch in dict) {
ch = dict[ch];
}
result.push(ch);
}
return result.join("");
};
return {getDict: function() {return dict;}, translate: translate};
}
function makeCeaserTrans(key) {
key = key % 26;
var U = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
L = U.toLowerCase(),
inTable = U + L,
outTable = U.slice(key) + U.slice(0, key) + L.slice(key) + L.slice(0, key);
return makeTrans(inTable, outTable);
}
// demo
var rot13 = makeCeaserTrans(13);
alert(rot13.translate('Rot13 is cool!'));
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.
9afbd1 No.4198
dict = "nopqrstuvwxyzabcdefghijklm"
translate char
| char != ' ' = dict !! ((ord char) - 61)
| otherwise = char
map translate "go eat shit"
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.