Browse Source

solve conflits2nd

Sjim 2 years ago
parent
commit
bea9142d64

+ 3 - 9
target/File/utils_3.py

@@ -1,9 +1,3 @@
-def build_model(args):
-    model = DeepGL(args.num_blocks)
-    if args.pretrained_path:
-        model.load_state_dict(torch.load(
-            os.path.join(args.pretrained_path, 'samples') + '/' + str(args.load_step) + '.pt'))
-
-    return model
-
-
+def pickle_dump(item, out_file):
+    with open(out_file, "wb") as opened_file:
+        pickle.dump(item, opened_file)

+ 8 - 5
target/File/utils_4.py

@@ -1,5 +1,8 @@
-def prepare_logger(path):
-    if not os.path.isdir(path):
-        os.makedirs(path)
-    logger = Logger(path)
-    return logger
+def write_to_clf(clf_data, save_file):
+    # Save dataset for text classification to file.
+    """
+    clf_data: List[List[str]] [[text1, label1],[text2,label2]...]
+    file format: tsv, row: text + tab + label
+    """
+    with open(save_file, 'w', encoding='utf-8') as f:
+        f.writelines("\n".join(["\t".join(str(r) for r in row) for row in clf_data]))

+ 0 - 26
target/Hash/EncrypC_3.py

@@ -1,26 +0,0 @@
-def encrypt(self):
-
-        # create a cipher object
-
-        cipher_object = AES.new(
-            self.hashed_key_salt["key"], AES.MODE_CFB, self.hashed_key_salt["salt"]
-        )
-
-        self.abort()  # if the output file already exists, remove it first
-
-        input_file = open(self.user_file, "rb")
-        output_file = open(self.encrypt_output_file, "ab")
-        done_chunks = 0
-
-        for piece in self.read_in_chunks(input_file, self.chunk_size):
-            encrypted_content = cipher_object.encrypt(piece)
-            output_file.write(encrypted_content)
-            done_chunks += 1
-            yield done_chunks / self.total_chunks * 100
-
-        input_file.close()
-        output_file.close()
-
-        # clean up the cipher object
-
-        del cipher_object

+ 0 - 20
target/Hash/EncryptionDecryption_2.py

@@ -1,20 +0,0 @@
-def encrypt(self, key, filename):
-        chunksize = 128 * 1024
-        outFile = os.path.join(os.path.dirname(filename), "(Secured)" + os.path.basename(filename))
-        filesize = str(os.path.getsize(filename)).zfill(16)
-        IV = Random.new().read(AES.block_size)
-        print(IV, len(IV))
-        encryptor = AES.new(key, AES.MODE_CBC, IV)
-
-        with open(filename, "rb") as infile:
-            with open(outFile, "wb") as outfile:
-                outfile.write(filesize.encode('utf-8'))
-                outfile.write(IV)
-                while True:
-                    chunk = infile.read(chunksize)
-                    if len(chunk) == 0:
-                        break
-                    elif len(chunk) % 16 != 0:
-                        chunk += b' ' * (16 - (len(chunk) % 16))
-                    outfile.write(encryptor.encrypt(chunk))
-        return outFile

+ 0 - 10
target/Hash/base64_2.py

@@ -1,10 +0,0 @@
-def encryptFile():
-    myFile = input("enter file to encrypt: ")
-    file = open(myFile,"r")
-    contents = file.read()
-    contents = contents.encode()
-    file = open(myFile, "w")
-    encoded = base64.b64encode(contents)
-    # the .decode() converts the bytes to str, taking off the b'...'
-    file.write(str(encoded))
-    print ("File is now encrypted... and the contents is unreadable")

+ 0 - 14
target/Hash/base64_3.py

@@ -1,14 +0,0 @@
-def decryptMessage():
-    pwd = "N3VIQUJmZ2pyNDVkZDRvMzNkZmd0NzBkZzlLOWRmcjJ0NWhCdmRm"
-    key = base64.b64decode(pwd) #the decoded version of this is the key.
-    value = input("Enter the decryption key: ").encode()
-    if value == key:
-        time.sleep(1)
-        message = input("Enter the message to decode: ")
-        decoded = base64.b64decode(message)
-        print (decoded)
-        menu()
-        
-    else:
-        print("Decryption key is wrong.")
-        menu()

+ 0 - 5
target/Hash/base64_4.py

@@ -1,5 +0,0 @@
-def encrypt():
-    password = input("Enter a message: ").encode()
-    encoded = base64.b64encode(password)
-    print (encoded.decode()) 
-    menu()

+ 0 - 3
target/Hash/base64_5.py

@@ -1,3 +0,0 @@
-def hashing(password):
-    hash1 = hashlib.md5(str.encode(password)).hexdigest()
-    print ("your hashed password is:", hash1,"\n")

+ 0 - 69
target/Hash/biometry_hash_5.py

@@ -1,69 +0,0 @@
-def fp_search():
-        
-    """
-    PyFingerprint
-    Copyright (C) 2015 Bastian Raschke <bastian.raschke@posteo.de>
-    All rights reserved.
-
-    @author: Bastian Raschke <bastian.raschke@posteo.de>
-    """
-
-
-    ## Search for a finger
-    ##
-
-    ## Tries to initialize the sensor
-    try:
-        f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000)
-
-        if ( f.verifyPassword() == False ):
-            raise ValueError('The given fingerprint sensor password is wrong!')
-
-    except Exception as e:
-        print('The fingerprint sensor could not be initialized!')
-        print('Exception message: ' + str(e))
-        exit(1)
-
-    ## Gets some sensor information
-    print('Currently stored templates: ' + str(f.getTemplateCount()))
-
-    ## Tries to search the finger and calculate hash
-    try:
-        print('Waiting for finger...')
-
-        ## Wait that finger is read
-        while ( f.readImage() == False ):
-            pass
-
-        ## Converts read image to characteristics and stores it in charbuffer 1
-        f.convertImage(0x01)
-
-        ## Searchs template
-        result = f.searchTemplate()
-
-        positionNumber = result[0]
-        accuracyScore = result[1]
-
-        if ( positionNumber == -1 ):
-            print('No match found!')
-            exit(0)
-        else:
-            print('Found template at position #' + str(positionNumber))
-            print('The accuracy score is: ' + str(accuracyScore))
-
-        ## OPTIONAL stuff
-        ##
-
-        ## Loads the found template to charbuffer 1
-        f.loadTemplate(positionNumber, 0x01)
-
-        ## Downloads the characteristics of template loaded in charbuffer 1
-        characterics = str(f.downloadCharacteristics(0x01))
-
-        ## Hashes characteristics of template
-        print('SHA-2 hash of template: ' + hashlib.sha256(characterics).hexdigest())
-
-    except Exception as e:
-        print('Operation failed!')
-        print('Exception message: ' + str(e))
-        exit(1)

+ 0 - 27
target/Hash/biometry_hash_8.py

@@ -1,27 +0,0 @@
-def encrypt(key, filename):
-	chunksize = 64*1024
-	#print filename
-	#print "4th time: ", key
-	outputFile = "(encrypted)"+filename
-	filesize = str(os.path.getsize(filename)).zfill(16)
-	IV = ''
-
-	for i in range(16):
-		IV += chr(random.randint(0, 0xFF))
-
-	encryptor = AES.new(key, AES.MODE_CBC, IV)
-
-	with open(filename, 'rb') as infile:
-		with open(outputFile, 'wb') as outfile:
-			outfile.write(filesize)
-			outfile.write(IV)
-			
-			while True:
-				chunk = infile.read(chunksize)
-				
-				if len(chunk) == 0:
-					break
-				elif len(chunk) % 16 != 0:
-					chunk += ' ' * (16 - (len(chunk) % 16))
-
-				outfile.write(encryptor.encrypt(chunk))

+ 0 - 12
target/Hash/crypto_4.py

@@ -1,12 +0,0 @@
-def __init__(self, data=None, truncate_to=None):
-        """ SHA-265d against length-extensions-attacks
-            with optional truncation of the hash
-
-        Args:
-            data: Initial string, optional
-            truncate_to: length to truncate the hash to, optional
-        """
-        self.h = sha256()
-        self.truncate_to = truncate_to
-        if data:
-            self.h.update(data)

+ 0 - 2
target/Hash/crypto_6.py

@@ -1,2 +0,0 @@
-def digest(self):
-        return sha256(self.h.digest()).digest()[:self.truncate_to]

+ 0 - 2
target/Hash/crypto_7.py

@@ -1,2 +0,0 @@
-def hexdigest(self):
-        return self.digest().encode('hex')

+ 0 - 7
target/Hash/dirist_14.py

@@ -1,7 +0,0 @@
-def hasher(key):
-	try:
-		key = key.encode()
-		x = hashlib.sha224(key).hexdigest()
-		return(int(str(x),16))
-	except:
-		return -1

+ 0 - 11
target/Hash/dirist_15.py

@@ -1,11 +0,0 @@
-def encrypt(key,text,dec=1):
-	if __name__ == '__main__':
-		encrypted = ""
-		key = hasher(key)
-		dupkey = key
-		for i in range(len(text)):
-			new = chr(ord(text[i])+ dec*(dupkey%10))
-			encrypted = encrypted + new
-			if dupkey==0: dupkey = key
-			dupkey = int(dupkey/10)
-		return encrypted

+ 0 - 4
target/Hash/hash_1.py

@@ -1,4 +0,0 @@
-def md5(string):
-    m = hashlib.md5()
-    m.update(string)
-    return m.digest()

+ 0 - 4
target/Hash/hash_2.py

@@ -1,4 +0,0 @@
-def sha256(string):
-    s = hashlib.sha256()
-    s.update(string)
-    return s.digest()

+ 0 - 21
target/Hash/hash_3.py

@@ -1,21 +0,0 @@
-def hash(argc):
-    """hash: various hashing functions.
-    
-    Usage:
-        hash (md5|sha256) FILE
-        hash (md5|sha256) --string STRING
-    """
-    
-    if argc.args['FILE']:
-        if argc.args['md5']:
-            return md5(open(argc.args['FILE']).read())
-
-        elif argc.args['sha256']:
-            return sha256(open(argc.args['FILE']).read())
-
-    elif argc.args['--string']:
-        if argc.args['md5']:
-            return md5(argc.args['STRING'])
-
-        elif argc.args['sha256']:
-            return sha256(argc.args['STRING'])

+ 0 - 27
target/Hash/md5_encryption_1.py

@@ -1,27 +0,0 @@
-def md5_encrypt(data, key):
-	if len(data) % 16 != 0:
-		data += (16 - (len(data) % 16)) * '\x00'
-
-	hash_block = []
-
-	output = ''
-	last_hash = ''
-	for c in data:
-		md5_ctx = hashlib.md5()
-		md5_ctx.update(c)
-		md5_ctx.update(key)
-		md5_ctx.update(last_hash)
-		hash_block.append(md5_ctx.digest())
-		last_hash = hash_block[-1]
-		if len(hash_block) == 16:
-			cur_block = ''
-			for b in hash_block:
-				cur_block += b
-
-			md5_ctx = hashlib.md5()
-			md5_ctx.update(cur_block)
-			last_hash = md5_ctx.digest()
-			output += cur_block + last_hash
-			hash_block = []
-
-	return output

+ 0 - 14
target/Hash/simple-hash_2.py

@@ -1,14 +0,0 @@
-def hash_pwd (string, salt=None):
-  msg = []
-
-  if salt == None:
-    salt = gen_salt(20)
-
-  for i, c in enumerate(string):
-    char_s = ord(salt[len(string) - i])
-    char_string = ord(c)
-    msg.append(chr((char_s + char_string) % 127))
-
-  res = ''.join(msg)
-
-  return (res + salt, salt)

+ 0 - 23
target/Pseudonym/anonymize_3.py

@@ -1,23 +0,0 @@
-def find_nhs_numbers(fn):
-    try:
-        f = open(fn, 'rb')
-    except IOError:
-        return None
-    locations = []
-    num = 0
-    while True:
-        c = f.read(1)
-        if c == '':
-            break
-        ascii_ = ord(c)
-
-        if ascii_ in (48, 49, 50, 51, 52, 53, 54, 55, 56, 57):
-            num += 1
-        else:
-            if num == 10:
-                startLocation = f.tell() - 11
-                f.seek(startLocation)
-                if validate_nhs_number(f.read(10)):
-                    locations.append(startLocation)
-            num = 0
-    return locations

+ 0 - 13
target/Pseudonym/anonymize_5.py

@@ -1,13 +0,0 @@
-def replace_nhs_numbers(fn, locations):
-
-    outFn = os.path.join(os.path.dirname(fn), "ANON_" + os.path.basename(fn))
-    with open(fn, 'rb') as f, open(outFn, 'wb') as out:
-
-        for location in locations:
-            buf = f.read(location - f.tell())
-            out.write(buf)
-
-            pseudo = str(get_pseudonym((int(f.read(10)))))
-            out.write(pseudo)
-
-        out.write(f.read())

+ 0 - 42
target/Pseudonym/anonymize_6.py

@@ -1,42 +0,0 @@
-def get_pseudonym(nhs_number):
-    global GENERATE_NEW
-
-    pseudo = LOOKUP.get(nhs_number)
-    if pseudo is not None:
-        return pseudo
-
-    if GENERATE_NEW is not True:
-        print("I have encountered a new NHS number (%d) with no pseudonym.\n"
-              "Should I generate new ones for any new NHS numbers I find "
-              "from now on?" % nhs_number)
-        response = raw_input("type y or n:")
-        if response == 'y':
-            GENERATE_NEW = True
-        else:
-            print("In that case, I will exit now.")
-            exit()
-
-    while True:
-        digits = []
-        s = ''
-        tot = 0
-        for i in range(9):
-            if i == 0:
-                digit = random.randint(1, 9)
-            else:
-                digit = random.randint(0, 9)
-            digits.append(digit)
-            s += str(digit)
-            tot += digit * (10 - i)  # (10 - i) is the weighting factor
-
-        checksum = 11 - (tot % 11)
-
-        if checksum == 11:
-            checksum = 0
-        if checksum != 10:  # 10 is an invalid nhs number
-            s += str(checksum)
-
-            pseudo = int(s)
-            LOOKUP[nhs_number] = pseudo
-
-            return pseudo

+ 0 - 20
target/Pseudonym/dataFrameAnonymizer_3.py

@@ -1,20 +0,0 @@
-def anonymize(self, df, k, l=0):
-
-        # Check inputs
-        if df is None or len(df) == 0:
-            raise Exception("Dataframe is empty")
-        if self.sensitive_attribute_columns is None or len(self.sensitive_attribute_columns) == 0:
-            raise Exception("Provide at least one sensitive attribute column")
-
-        if not self.feature_columns:
-            self.init_feature_colums(df)
-
-        if self.avg_columns:
-            for c in self.avg_columns:
-                if not is_numeric_dtype(df[c]):
-                    raise Exception("Column " + c + " is not numeric and average cannot be calculated.")
-
-        mondrian = MondrianAnonymizer(df, self.feature_columns, self.sensitive_attribute_columns)
-        partitions = mondrian.partition(k, l)
-        dfa = self.build_anonymized_dataframe(df, partitions)
-        return dfa

+ 0 - 5
target/Pseudonym/pseudodepseudonimizer_2.py

@@ -1,5 +0,0 @@
-def dots2numberedDots(all_text, replace_string="..."):
-    replace_string = re.escape(replace_string)
-    dots_regex = re.compile(r"(\s)[A-Z]?\[?({})\]?(\s)".format(replace_string))
-    all_text = dots_regex.sub(dots_repl, all_text)
-    return all_text