Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import string
- uc = string.ascii_uppercase
- lc = string.ascii_lowercase
- myrot = uc + lc
- drot = {}
- for i in range(26*2):
- b = (i + 13)%26
- idx = b if i < 26 else b + 26
- drot[myrot[i]] = myrot[idx]
- def rot13(mystr):
- newstr = "".join([drot[c] if c in drot else c for c in mystr])
- return newstr
- print(rot13("Rai is such a cute latino girl"))
- rot13char = lambda c: chr((((ord(c) & 0b11111) + 12) % 26 + 1)+(ord(c) & 0b1100000))
- def bitrot13(mystr):
- newstr = "".join([rot13char(c) if c in myrot else c for c in mystr])
- return newstr
- teststr = '''
- >>> import timeit>>> timeit.timeit('"-".join(str(n) for n in range(100))', number=10000)0.8187260627746582>>> timeit.timeit('"-".join([str(n) for n in range(100)])', number=10000)0.7288308143615723>>> timeit.timeit('"-".join(map(str, range(100)))', number=10000)0.5858950614929199Note however that timeit will automatically determine the number of repetitions only when the command-line interface is used. In the Examples section you can find more advanced examples.
- '''
- if __name__ == '__main__':
- import timeit
- print("Pella version")
- print(timeit.timeit("rot13(teststr)", setup="from __main__ import rot13, teststr", number= 1000))
- print("Bit version")
- print(timeit.timeit("bitrot13(teststr)", setup="from __main__ import bitrot13, teststr", number= 1000))
Advertisement
Add Comment
Please, Sign In to add comment