Guest User

Untitled

a guest
Aug 12th, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. #
  4. # author: @090h
  5. #
  6.  
  7. # #i#<L4w1u0q)mT9Q ----- ????????
  8. # 1evryyone lies6 ----- 44,~yteU<<*sZOe
  9. # 1234567 ----- )Wj~5Kb
  10. # 1234568 ----- *Wj~5Kc
  11. # 2345678 ----- 1Ym$:Qi
  12. # abcdef ----- FX=#hP
  13. # abcdef1 ----- YY>$iQb
  14. # hackers ----- ]_D1vj_
  15. # 1337hackers ----- |\o(pS8%j^S
  16. # hackers1337 ----- UcH5znct)<S
  17. # task for cryptoanalysis ----- !{p]]E6**ma\ND5vfI72'pe
  18. # you will never break this cipher! ----- q:11*saOO?&|cWW;/tWDD:$mbbG2$lSGH
  19. #
  20. # Flag is MD5(????????)
  21.  
  22. def encrypt(input):
  23.     output = ''
  24.     val = 0
  25.     buff = []
  26.  
  27.     for i in xrange(len(input)):
  28.         val = ord(input[i]) - 32
  29.  
  30.         if i > 0: val += int(buff[i - 1])
  31.         else: val += len(input) + 13
  32.  
  33.         if val > 94: val -= 94
  34.  
  35.         vali = int(val)
  36.  
  37.         if i == len(input) - 1:
  38.             temp = int(buff[0]) + val
  39.             #print temp
  40.             if temp > 94: temp -= 94
  41.             print('buff[0] %i -> %i'% (int(buff[0]), temp))
  42.             buff[0] = temp
  43.  
  44.         buff.append(vali)
  45.     print buff
  46.  
  47.     for i in xrange(len(input)):
  48.         output += (chr(buff[i] + 32))
  49.     return output
  50.  
  51. def decrypt(input):
  52.     val = 0
  53.     buff = []
  54.     output = [0 for x in xrange(len(input))]
  55.  
  56.     for i in xrange(len(input)):
  57.         q = ord(input[i])-32
  58.         buff.append(q)
  59.     print 'BUFF', buff
  60.  
  61.     for i in range(len(input)-1, 0, -1):
  62.         vali = buff[len(input)-1]
  63.         print 'VAL', vali
  64.         temp = buff[0]
  65.         print "TEMP", temp
  66.         if temp < 94:
  67.             temp += 94
  68.         temp -= vali
  69.         print "TEMP", temp
  70.         print('buff[0] %i -> %i'% (buff[0], temp))
  71.         buff[0] = temp
  72.         break
  73.  
  74.     print '>>>', buf
  75.     for i in xrange(len(input)):
  76.         val = buff[i]
  77.         if i > 0:
  78.             val -= buff[i - 1]
  79.         else:
  80.             val -= int(len(input) + 13)
  81.  
  82.         print 'VAL->>>', val + 32
  83.         if val < 0:
  84.             output[i] = val + 94 + 32
  85.             print 'out:', output[1]
  86.         else:
  87.             output[i] = val +  32
  88.  
  89.  
  90.     return output
  91.  
  92. if __name__ == '__main__':
  93.     res = encrypt('1234567')
  94.     buf = []
  95.     for a in res:
  96.         buf.append(ord(a))
  97.     print buf
  98.     print res
  99.  
  100.     print '-'*30+'DECRYPT'+'-'*30
  101.     #c  = ')Wj~5Kb'
  102.     #c  = 'q:11*saOO?&|cWW;/tWDD:$mbbG2$lSGH'
  103.     #c  = ']_D1vj_'
  104.  
  105.     c  = '#i#<L4w1u0q)mT9Q'
  106.     buf = decrypt(c)
  107.     print c,'->', buf
  108.     q = ''
  109.     for b in buf:
  110.         q += chr(b)
  111.  
  112.     print q
Advertisement
Add Comment
Please, Sign In to add comment