Krautkanal.com

Veröffentlicht am 2016-03-20 23:05:16 in /prog/

/prog/ 8559: Rot13 thread! key = 13 U = 'ABCDEFGHIJKLMNOP...

snowshade Avatar
snowshade:#8559

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))

okcoker Avatar
okcoker:#8564

Was ist mit Zahlen und Satzzeichen?

vicivadeline Avatar
vicivadeline:#8565

Warum nicht
U = (chr('A' + i) for i in range(26))
?

vicivadeline Avatar
vicivadeline:#8566

>>8565
Da fehlt noch ein ord().

hammedk Avatar
hammedk:#8571

>>8565

Not as readable.

pdugan19 Avatar
pdugan19:#8572

>>8564>>8564

It leaves them unchanged.

dwardt Avatar
dwardt:#8573

>>8572
Ok, das habe ich jetzt auch gemerkt.

kuldarkalvik Avatar
kuldarkalvik:#8575


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!"));

vaughanmoffitt Avatar
vaughanmoffitt:#8577


rot13 = str.maketrans("ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz",
                      "NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm")
print("rot13 sucks!".translate(rot13))

millinet Avatar
millinet:#8579

echo "Zvg genafyngr trug rf nz rvasnpufgra." | tr "A-Za-z" "N-ZA-Mn-za-m"

andrewofficer Avatar
andrewofficer:#8585

import codecs
codecs.encode('bla', 'rot_13')

sindresorhus Avatar
sindresorhus:#8600

var rot13 = require("rot13-transform");

ReadableStreamString("node bestes javascript")
.pipe(rot13())
.pipe(process.stdout);

Neuste Fäden in diesem Brett: