def unTwist8(rand):
    val = rand
    val = MT.unRShift(val, 5)
    val = MT.unLShift(val, 3, 0xef)
    val = MT.unLShift(val, 2, 0x9d)
    val = MT.unRShift(val, 4)
    return val
def unTwist(rand):
    val = rand
    val = MT.unRShift(val, 18)
    val = MT.unLShift(val, 15, 0xefc60000)
    val = MT.unLShift(val, 7, 0x9d2c5680)
    val = MT.unRShift(val, 11)
    return val
def unTwist(rand):
    val = rand  
    val = MT.unRShift(val, 18)
    val = MT.unLShift(val, 15, 0xefc60000)
    val = MT.unLShift(val, 7, 0x9d2c5680)
    val = MT.unRShift(val, 11)
    return val
def unTwist8(rand):
    val = rand
    val = MT.unRShift(val, 5)
    val = MT.unLShift(val, 3 , 0xef)
    val = MT.unLShift(val, 2, 0x9d)
    val = MT.unRShift(val, 4)
    return val

# 
# seed = int(time.time())
# List = MT.init(seed)
# Test = []
# for i in range(1,624):
#     val = MT.extract_numbers(List, i)[1]
#     val = unTwist(val)
#     Test.append(val)
# 
# total = len(Test)
# right = 0
# for i,j in zip(List[1:], Test):
#     if i == j:
#         right += 1
# print right / 1.0 / total

    
def decrypt(cipherText, seed):
    MT = rnd.init8(seed)
    plainText = ""
    i = 1
    for c in cipherText:
        rand = rnd.extract_numbers8(MT, i)[1]
        plainText += chr(rand ^ (ord(c)))
        i += 1
    return plainText
def encrypt(Message, seed):
    MT = rnd.init8(seed)
    cipherText = ""
    i = 1
    for c in Message:
        rand = rnd.extract_numbers8(MT, i)[1]
        cipherText += chr(rand ^ (ord(c)))
        i += 1
    return cipherText
def decrypt(cipherText, seed):
    MT = rnd.init8(seed)
    plainText = ""
    i = 1
    for c in cipherText:
        rand = rnd.extract_numbers8(MT, i)[1]
        plainText += chr(rand ^ (ord(c)))
        i += 1
    return plainText
def encrypt(Message, seed):
    MT = rnd.init8(seed)
    cipherText = ""
    i = 1
    for c in Message:
        rand = rnd.extract_numbers8(MT, i)[1]
        cipherText += chr(rand ^ (ord(c)))
        i += 1
    return cipherText
def Trace(val, index, cipherText):
    forward = cipherText[index + 1:]
    plainText = chr(ord(cipherText[index]) ^ val)
    for c in forward:
        orig = un.unTwist8(val)
        next = rnd.getNext8(orig, index)
        val = rnd.getTwist(next)
        index += 1
        plainText += chr((ord(c) ^ val))
    back = cipherText[0:index]
    return plainText
def Trace(val, index, cipherText):
    forward = cipherText[index + 1 :]
    plainText = chr(ord(cipherText[index]) ^ val)
    for c in forward:
        orig = un.unTwist8(val)
        next = rnd.getNext8(orig, index)
        val = rnd.getTwist(next)
        index += 1
        plainText += chr((ord(c) ^ val))
    back = cipherText[0:index]
    return plainText
Example #11
0
def waitRand():
    delay = random.randrange(20,60)
    time.sleep(delay)
    seed = int(time.time())
    delay = random.randrange(20,60)
    time.sleep(delay)
    return MT.getFirst(seed), seed
Example #12
0
import numpy
import k_Nearest_Neighbors
import sys
sys.path.append('D:\Machine Learning\Machine-Learning\Random_Data_Generator')
import RandGen

Generator = RandGen.RandomDataGenerator()
DataList = Generator.GenerateBinaryData(100, [1, -3, 1], Poly=True, noise=0)
test = k_Nearest_Neighbors.kNearestNeighbors(DataList)
test.Visualization()
#test.DataCondensing(10)
testData = numpy.random.rand(50, 2)
testData = testData * 10
for i in testData:
    test.KNearestNeighbors(10, i, Visual=True)
test.Visualization()
Example #13
0
 def ranGenFunc(self):
     import RandGen
     reload(RandGen)
     instance = RandGen.Generator()
     instance.create()
        for c in cipherText[len(cipherText) - loc:]:
            if chr((ord(c) ^ i)) == "A":
                return i, j
            j += 1


def Trace(val, index, cipherText):
    forward = cipherText[index + 1:]
    plainText = chr(ord(cipherText[index]) ^ val)
    for c in forward:
        orig = un.unTwist8(val)
        next = rnd.getNext8(orig, index)
        val = rnd.getTwist(next)
        index += 1
        plainText += chr((ord(c) ^ val))
    back = cipherText[0:index]
    return plainText


print rnd.getFirst8(1700000)

exit()
known = "A" * 14
num = random.randrange(1, 10)
unknown = os.urandom(num)
Message = unknown + known
seed = random.randrange(2**16, 2**17 - 1)
cipherText = encrypt(Message, seed)

rand, index = findAByte("A", cipherText, 14)
print Trace(rand, index, cipherText)
            if chr((ord(c) ^ i)) == "A":
                return i, j
            j += 1


def Trace(val, index, cipherText):
    forward = cipherText[index + 1 :]
    plainText = chr(ord(cipherText[index]) ^ val)
    for c in forward:
        orig = un.unTwist8(val)
        next = rnd.getNext8(orig, index)
        val = rnd.getTwist(next)
        index += 1
        plainText += chr((ord(c) ^ val))
    back = cipherText[0:index]
    return plainText


print rnd.getFirst8(1700000)

exit()
known = "A" * 14
num = random.randrange(1, 10)
unknown = os.urandom(num)
Message = unknown + known
seed = random.randrange(2 ** 16, 2 ** 17 - 1)
cipherText = encrypt(Message, seed)

rand, index = findAByte("A", cipherText, 14)
print Trace(rand, index, cipherText)
Example #16
0
'''
Created on Jun 26, 2015

@author: mewolot
'''

import RandGen as MT
import time
import random

def waitRand():
    delay = random.randrange(20,60)
    time.sleep(delay)
    seed = int(time.time())
    delay = random.randrange(20,60)
    time.sleep(delay)
    return MT.getFirst(seed), seed

maxWait = 150
minWait = 20

rand, verifier = waitRand()
cur = int(time.time())

for i in range(minWait,maxWait):
    test = MT.getFirst(cur - i)
    if test == rand:
        print cur - i
        print verifier
        break
print "Done"