rot_13.py (1897B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\stdlib\encodings\rot_13.py 2 import codecs 3 4 class Codec(codecs.Codec): 5 6 def encode(self, input, errors = 'strict'): 7 return codecs.charmap_encode(input, errors, encoding_map) 8 9 def decode(self, input, errors = 'strict'): 10 return codecs.charmap_decode(input, errors, decoding_map) 11 12 13 class IncrementalEncoder(codecs.IncrementalEncoder): 14 15 def encode(self, input, final = False): 16 return codecs.charmap_encode(input, self.errors, encoding_map)[0] 17 18 19 class IncrementalDecoder(codecs.IncrementalDecoder): 20 21 def decode(self, input, final = False): 22 return codecs.charmap_decode(input, self.errors, decoding_map)[0] 23 24 25 class StreamWriter(Codec, codecs.StreamWriter): 26 pass 27 28 29 class StreamReader(Codec, codecs.StreamReader): 30 pass 31 32 33 def getregentry(): 34 return codecs.CodecInfo(name='rot-13', encode=Codec().encode, decode=Codec().decode, incrementalencoder=IncrementalEncoder, incrementaldecoder=IncrementalDecoder, streamwriter=StreamWriter, streamreader=StreamReader) 35 36 37 decoding_map = codecs.make_identity_dict(range(256)) 38 decoding_map.update({65: 78, 39 66: 79, 40 67: 80, 41 68: 81, 42 69: 82, 43 70: 83, 44 71: 84, 45 72: 85, 46 73: 86, 47 74: 87, 48 75: 88, 49 76: 89, 50 77: 90, 51 78: 65, 52 79: 66, 53 80: 67, 54 81: 68, 55 82: 69, 56 83: 70, 57 84: 71, 58 85: 72, 59 86: 73, 60 87: 74, 61 88: 75, 62 89: 76, 63 90: 77, 64 97: 110, 65 98: 111, 66 99: 112, 67 100: 113, 68 101: 114, 69 102: 115, 70 103: 116, 71 104: 117, 72 105: 118, 73 106: 119, 74 107: 120, 75 108: 121, 76 109: 122, 77 110: 97, 78 111: 98, 79 112: 99, 80 113: 100, 81 114: 101, 82 115: 102, 83 116: 103, 84 117: 104, 85 118: 105, 86 119: 106, 87 120: 107, 88 121: 108, 89 122: 109}) 90 encoding_map = codecs.make_encoding_map(decoding_map) 91 92 def rot13(infile, outfile): 93 outfile.write(infile.read().encode('rot-13')) 94 95 96 if __name__ == '__main__': 97 import sys 98 rot13(sys.stdin, sys.stdout)