Pella86

Untitled

Aug 7th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. import string
  2.  
  3. uc = string.ascii_uppercase
  4. lc = string.ascii_lowercase
  5.  
  6. myrot = uc + lc
  7.  
  8. drot = {}
  9.  
  10. for i in range(26*2):
  11.     b = (i + 13)%26
  12.     idx = b if i < 26 else b + 26
  13.     drot[myrot[i]] = myrot[idx]        
  14.  
  15. def rot13(mystr):
  16.     newstr = "".join([drot[c] if c in drot else c for c in mystr])
  17.     return newstr
  18.  
  19. print(rot13("Rai is such a cute latino girl"))
  20.  
  21.  
  22. rot13char = lambda c: chr((((ord(c) & 0b11111) + 12) % 26 + 1)+(ord(c) & 0b1100000))    
  23.  
  24. def bitrot13(mystr):
  25.     newstr = "".join([rot13char(c) if c in myrot else c for c in mystr])
  26.     return newstr
  27.                    
  28. teststr = '''
  29. >>> 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.
  30. '''
  31.  
  32.  
  33.  
  34. if __name__ == '__main__':
  35.     import timeit
  36.     print("Pella version")
  37.     print(timeit.timeit("rot13(teststr)", setup="from __main__ import rot13, teststr", number= 1000))
  38.  
  39.     print("Bit version")
  40.     print(timeit.timeit("bitrot13(teststr)", setup="from __main__ import bitrot13, teststr", number= 1000))
Advertisement
Add Comment
Please, Sign In to add comment