SHARE
TWEET

Untitled

a guest Dec 30th, 2013 1,203 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python2
  2. import socket
  3. import random
  4. import sys
  5. import os
  6. import signal
  7. import re
  8. import array
  9.  
  10. # define of the local right shift function (>>>)
  11. def rshift(val, n): return (val % 0x100000000) >> n
  12. # define some magic XOR functions to be able to extract the state's number from the outputs server
  13. def unBitshiftLeftXor(value, shift, mask):
  14.         i = 0
  15.         result = 0
  16.         while (i * shift < 32):
  17.                 partMask = (rshift(-1, (32 - shift))) << (shift * i)
  18.                 part = value & partMask
  19.                 value ^= (part << shift) & mask
  20.                 result |= part
  21.                 i+=1
  22.         return result
  23.  
  24. def unBitshiftRightXor(value, shift):
  25.         i = 0;
  26.         result = 0;
  27.         while (i * shift < 32):
  28.                 partMask = rshift((-1 << (32 - shift)) , (shift * i))
  29.                 part = value & partMask
  30.                 value ^= rshift(part, shift)
  31.                 result |= part
  32.                 i+=1
  33.         return result
  34. # this function give us long number of the MT internal state
  35. def back_state(out):
  36.         value = unBitshiftRightXor(out, 18)
  37.         value = unBitshiftLeftXor(value, 15, 4022730752)
  38.         value = unBitshiftLeftXor(value, 7, 2636928640)
  39.         return unBitshiftRightXor(value, 11)
  40.  
  41. # state of the server
  42. state=[]
  43. # our random object
  44. ran = random.Random()
  45. # socket things..
  46. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  47. s.connect(("88.198.89.194", 8888))
  48. data = s.recv(1024)
  49. print(data)
  50. # take it!
  51. for i in range(0,312):
  52.         print "at "+str(i)
  53.         data = s.recv(1024)
  54.         print(data)
  55.         s.send("1000\n")
  56.         data = s.recv(1024)
  57.         print(data)
  58.         rgx=re.search("Nope, that was wrong, correct would have been (.+)\.\.\.",data)
  59.         nmb=int(rgx.groups()[0]) # since we get a 64bit number we have to split it into 32bit numbers
  60.         f_nmb=nmb>>32
  61.         s_nmb=nmb & 0xffffffff
  62.         state.append(back_state(s_nmb)) # push them inside
  63.         state.append(back_state(f_nmb))
  64.  
  65. # good state ends with a 624L
  66. state.append(624L)
  67. print state
  68. print len(state)
  69.  
  70. # now the fun begins starting with setting the state
  71. ran.setstate((3, tuple(state),None))
  72. data = s.recv(1024)
  73. print(data)
  74. # lets "guess" this numbers...
  75. for i in range(1,11):
  76.         print i
  77.         n=ran.getrandbits(64)
  78.         print n
  79.         s.send(str(n)+"\n")
  80.         data = s.recv(1024)
  81.         print(data)
  82.         data = s.recv(1024)
  83.         print(data)
  84.  
  85. print "out"
  86. data = s.recv(1024)
  87. print(data)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top