Esempio n. 1
0
    def shuffle(self, bcHashStr):
        """
        Shuffle the elements in the listCreate a FairShuffle object.
		
        Arguments: bcHashStr - a 32 byte hash
        Returns:   a list or tuple of a fair shuffle based on hash
        """
        if not len(bcHashStr) == EXPECTED_HASH_LENGTH:
            raise FairShuffleError('invalid blockchain hash value - must be %d bytes'
                % EXPECTED_HASH_LENGTH)
        
        # Quickly return waste of time shuffles
        if len(self._items) == 0:
            return([])
        elif len(self._items) == 1:
            if isinstance(self._items, tuple):
                return (self._items[0],)
            else:
                return [self._items[0],]

        # A 32-bit unsigned integer is enough, and this was the only
        # way to get Python2/Python3 PRNGs compatible with each other.
        crc = binascii.crc32(bcHashStr) & 0xffffffff

        random.seed(crc)        
        lst = list(self._items)
        random.shuffle(lst)

        if isinstance(self._items, tuple):
            return tuple(lst)
        else:
            return lst
Esempio n. 2
0
 def reseed(self, anonymous_student_id=None, upseed=0):
     """
     Reseed the random seed to a specific value (used to recreate student data sets)
     """
     try:
         randomseed = int(anonymous_student_id, 16)+upseed
     except:
         randomseed = 1+upseed
     random.seed(randomseed)
Esempio n. 3
0
 def reseed(self, upseed=None):
     """
     Reseed the random seed to a specific value (used to recreate student data sets)
     """
     if upseed is None:
         upseed = self.upseed
     try:
         randomseed = int(self.anonymous_student_id, 16) + upseed
     except:
         randomseed = 1 + upseed
     random.seed(randomseed)
Esempio n. 4
0
passwd_user = input("Gib dein Passwort ein: ")
lenght = input("Wie Lange soll dein Passwort sein?: ")

length_passwd = len(passwd_user)

passwd_user = int(passwd_user)
lenght = int(lenght)

zahl_1 = (int(str(passwd_user)[:1]))
zahl_2 = (int(str(passwd_user)[:2]))
zahl_3 = (int(str(passwd_user)[:3]))
zahl_4 = (int(str(passwd_user)[:4]))
zahl_5 = (int(str(passwd_user)[:5]))
zahl_6 = (int(str(passwd_user)[:6]))

random2.seed(62500)
generate_random_key = random2.randint(1, 512)

number_nfol = zahl_1 * zahl_2 * zahl_3 * zahl_4 * zahl_5 * zahl_6

calcs = [
    number_nfol**generate_random_key, number_nfol**length_passwd,
    generate_random_key**length_passwd
]

for i in tqdm(calcs):
    time.sleep(2)
#key_phrase = number_nfol ** generate_random_key ** length_passwd

n_0 = calcs[0]
n_1 = calcs[1]
Esempio n. 5
0
# This little program offsets the samples of a WAV file by delta in the range
# -3 to 3. The result appears to be still hearable (though there are some
# artefacts). It was written as an experiment to see if I can demonstrate that
# losslesly compressing a 40 MB audio file to 20 kilo-Bytes was not
# realistic.

# TODO:
# * Make the code portable to python 3.
# * Optimize the runtime speed.
# * Convert to use some command line arguments.

import io
import random2
import struct

random2.seed(24)

def process(i):
    d = random2.randint(-3,3)
    ret = i + d
    return (0 if ret < 0 else (65535 if ret > 65535 else ret))

inp = io.open('out.wav', 'rb')
out = io.open('processed.wav', 'wb')

out.write(inp.read(100*4))

b = inp.read(2)
while b:
    out.write(struct.pack('H', process(struct.unpack('H', b)[0])))
    b = inp.read(2)
# This little program offsets the samples of a WAV file by delta in the range
# -3 to 3. The result appears to be still hearable (though there are some
# artefacts). It was written as an experiment to see if I can demonstrate that
# losslesly compressing a 40 MB audio file to 20 kilo-Bytes was not
# realistic.

# TODO:
# * Optimize the runtime speed.
# * Convert to use some command line arguments.

import io
import random2
import struct

random2.seed(24)

def process(i):
    d = random2.randint(-3,3)
    ret = i + d
    return (0 if ret < 0 else (65535 if ret > 65535 else ret))

inp = io.open('out.wav', 'rb')
out = io.open('processed.wav', 'wb')

out.write(inp.read(100*4))

b = inp.read(2)
while b:
    out.write(struct.pack('H', process(struct.unpack('H', b)[0])))
    b = inp.read(2)