Skip to content

Commit

Permalink
Merge remote-tracking branch 'daedalus/master' into dev
Browse files Browse the repository at this point in the history
* daedalus/master:
  'Refactored by Sourcery'
  2to3 and blackify code
  1GB bloom filter, clean up
  • Loading branch information
kenorb committed Nov 3, 2024
2 parents b55a375 + fd3f4ad commit 743e446
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 142 deletions.
7 changes: 6 additions & 1 deletion bloom.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdint.h>

/* 2^32 bits */
#define BLOOM_SIZE (1024*1024*1024)
#define BLOOM_SIZE (512*1024*1024*2)

#define BLOOM_SET_BIT(N) (bloom[(N)>>3] = bloom[(N)>>3] | (1<<((N)&7)))
#define BLOOM_GET_BIT(N) ( ( bloom[(N)>>3]>>((N)&7) )&1)
Expand Down Expand Up @@ -33,6 +33,11 @@
#define BH17(N) (N[2]<<24|N[3]>> 8)
#define BH18(N) (N[3]<<24|N[4]>> 8)
#define BH19(N) (N[4]<<24|N[0]>> 8)
#define BH20(N) (N[0]<<16|N[1]>>24)
#define BH21(N) (N[1]<<16|N[2]>>24)
#define BH22(N) (N[2]<<16|N[3]>>24)
#define BH23(N) (N[3]<<16|N[4]>>24)
#define BH24(N) (N[4]<<16|N[0]>>24)

#define BH20(N) (N[0]<<16|N[1]>>24)
#define BH21(N) (N[1]<<16|N[2]>>24)
Expand Down
4 changes: 2 additions & 2 deletions hex2blf.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "bloom.h"
#include "hash160.h"

const double k_hashes = 20;
const double m_bits = 4294967296;
const double k_hashes = 25;
const double m_bits = 4294967296*2;

int main(int argc, char **argv) {
hash160_t hash;
Expand Down
2 changes: 1 addition & 1 deletion scripts/generators/2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
for line in file2.lines():
id_ = line.split()[0]
if id_ in ids:
found.append("{} {}".format(ids[id_], line))
found.append(f"{ids[id_]} {line}")
45 changes: 22 additions & 23 deletions scripts/generators/3.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,33 @@
import random


help_message = '''
help_message = """
Code Phrase Generator
-n <x> or --number <x>: Number of sample code phrases given. (Default is 5)
-p <prefix> or --prefix <prefix>: Uses a prefix word along with a random codeword instead of two codewords.
-w <file> or --wordlist <file>: Uses another wordlist to generate code phrases from.
'''
"""

CODEWORDS = open('wordlist.txt', 'r').readlines()
CODEWORDS = open("wordlist.txt", "r").readlines()


class Usage(Exception):
def __init__(self, msg):
self.msg = msg


def generate(prefix=False, number=5):
while number > 0:
if prefix == 'TRUE':
word1 = PREFIXES[int(random.uniform(0,len(PREFIXES)))]
if prefix == "TRUE":
word1 = PREFIXES[int(random.uniform(0, len(PREFIXES)))]
elif prefix:
word1 = prefix
else:
word1 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
word1 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]

word2 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
word3 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
print "%s%s%s" % (word1.rstrip(), word2.rstrip(), word3.rstrip())
word2 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]
word3 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]
print(f"{word1.rstrip()}{word2.rstrip()}{word3.rstrip()}")

number -= 1

Expand All @@ -54,8 +55,10 @@ def main(argv=None):
argv = sys.argv
try:
try:
opts, args = getopt.getopt(argv[1:], "hn:p:i:vw:", ["help", "number=", "prefix=", "wordlist="])
except getopt.error, msg:
opts, args = getopt.getopt(
argv[1:], "hn:p:i:vw:", ["help", "number=", "prefix=", "wordlist="]
)
except getopt.error as msg:
raise Usage(msg)

# option processing
Expand All @@ -67,23 +70,19 @@ def main(argv=None):
if option in ("-n", "--number"):
number = int(value)
if option in ("-w", "--wordlist"):
global CODEWORDS
print "Importing: %s" % value
CODEWORDS = open(value, 'r').readlines()
global CODEWORDS
print(f"Importing: {value}")
CODEWORDS = open(value, "r").readlines()
if option in ("-p", "--prefixe"):

print value

if (value):
prefix = value
else:
prefix = 'TRUE'
print(value)

prefix = value if value else "TRUE"
generate(prefix, number)

except Usage, err:
print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
print >> sys.stderr, "\t for help use --help"
except Usage as err:
print(sys.argv[0].split("/")[-1] + ": " + str(err.msg), file=sys.stderr)
print("\t for help use --help", file=sys.stderr)
return 2


Expand Down
71 changes: 37 additions & 34 deletions scripts/generators/generate12words.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,49 @@
import getopt
import random

#sys.stdout = open('output.txt','wt')
# sys.stdout = open('output.txt','wt')

help_message = '''
help_message = """
Bip39 12 Word Random Generator By TheRealLordFractal
Output File Saved as 12words.txt
Command Exntensions:
-n <x> or --number <x>: Number of sample code phrases given. (Default is 5)
-w <file> or --wordlist <file>: Uses another wordlist to generate code phrases from.
'''
"""

CODEWORDS = open("wordlist.txt", "r").readlines()
outputtxt = open("12words.txt", "w")

CODEWORDS = open('wordlist.txt', 'r').readlines()
outputtxt = open('12words.txt', 'w')

class Usage(Exception):
def __init__(self, msg):
self.msg = msg


def generate(prefix=False, number=5):
while number > 0:
if prefix == 'TRUE':
print ("Not Supported.")
# word1 = PREFIXES[int(random.uniform(0,len(PREFIXES)))]
if prefix == "TRUE":
print("Not Supported.")
# word1 = PREFIXES[int(random.uniform(0,len(PREFIXES)))]
elif prefix:
word1 = prefix
else:
word1 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
word2 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
word3 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
word4 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
word5 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
word6 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
word7 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
word8 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
word9 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
word10 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
word11 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
word12 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
print >> outputtxt, "%s %s %s %s %s %s %s %s %s %s %s %s" % (word1.rstrip(), word2.rstrip(), word3.rstrip(), word4.rstrip(), word5.rstrip(), word6.rstrip(), word7.rstrip(), word8.rstrip(), word9.rstrip(), word10.rstrip(), word11.rstrip(), word12.rstrip())
word1 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]
word2 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]
word3 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]
word4 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]
word5 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]
word6 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]
word7 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]
word8 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]
word9 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]
word10 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]
word11 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]
word12 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]
print(
f"{word1.rstrip()} {word2.rstrip()} {word3.rstrip()} {word4.rstrip()} {word5.rstrip()} {word6.rstrip()} {word7.rstrip()} {word8.rstrip()} {word9.rstrip()} {word10.rstrip()} {word11.rstrip()} {word12.rstrip()}",
file=outputtxt,
)

number -= 1

Expand All @@ -62,8 +67,10 @@ def main(argv=None):
argv = sys.argv
try:
try:
opts, args = getopt.getopt(argv[1:], "hn:p:i:vw:", ["help", "number=", "prefix=", "wordlist="])
except getopt.error, msg:
opts, args = getopt.getopt(
argv[1:], "hn:p:i:vw:", ["help", "number=", "prefix=", "wordlist="]
)
except getopt.error as msg:
raise Usage(msg)

# option processing
Expand All @@ -76,22 +83,18 @@ def main(argv=None):
number = int(value)
if option in ("-w", "--wordlist"):
global CODEWORDS
print "Importing: %s" % value
CODEWORDS = open(value, 'r').readlines()
print(f"Importing: {value}")
CODEWORDS = open(value, "r").readlines()
if option in ("-p", "--prefixe"):

print value

if (value):
prefix = value
else:
prefix = 'TRUE'
print(value)

prefix = value if value else "TRUE"
generate(prefix, number)

except Usage, err:
print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
print >> sys.stderr, "\t for help use --help"
except Usage as err:
print(sys.argv[0].split("/")[-1] + ": " + str(err.msg), file=sys.stderr)
print("\t for help use --help", file=sys.stderr)
return 2


Expand Down
43 changes: 21 additions & 22 deletions scripts/generators/generate2words.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,32 @@
import random


help_message = '''
help_message = """
Code Phrase Generator
-n <x> or --number <x>: Number of sample code phrases given. (Default is 5)
-p <prefix> or --prefix <prefix>: Uses a prefix word along with a random codeword instead of two codewords.
-w <file> or --wordlist <file>: Uses another wordlist to generate code phrases from.
'''
"""

CODEWORDS = open('wordlist.txt', 'r').readlines()
CODEWORDS = open("wordlist.txt", "r").readlines()


class Usage(Exception):
def __init__(self, msg):
self.msg = msg


def generate(prefix=False, number=5):
while number > 0:
if prefix == 'TRUE':
word1 = PREFIXES[int(random.uniform(0,len(PREFIXES)))]
if prefix == "TRUE":
word1 = PREFIXES[int(random.uniform(0, len(PREFIXES)))]
elif prefix:
word1 = prefix
else:
word1 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
word1 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]

word2 = CODEWORDS[int(random.uniform(0,len(CODEWORDS)))]
print "%s %s" % (word1.rstrip(), word2.rstrip())
word2 = CODEWORDS[int(random.uniform(0, len(CODEWORDS)))]
print(f"{word1.rstrip()} {word2.rstrip()}")

number -= 1

Expand All @@ -53,8 +54,10 @@ def main(argv=None):
argv = sys.argv
try:
try:
opts, args = getopt.getopt(argv[1:], "hn:p:i:vw:", ["help", "number=", "prefix=", "wordlist="])
except getopt.error, msg:
opts, args = getopt.getopt(
argv[1:], "hn:p:i:vw:", ["help", "number=", "prefix=", "wordlist="]
)
except getopt.error as msg:
raise Usage(msg)

# option processing
Expand All @@ -66,23 +69,19 @@ def main(argv=None):
if option in ("-n", "--number"):
number = int(value)
if option in ("-w", "--wordlist"):
global CODEWORDS
print "Importing: %s" % value
CODEWORDS = open(value, 'r').readlines()
global CODEWORDS
print(f"Importing: {value}")
CODEWORDS = open(value, "r").readlines()
if option in ("-p", "--prefixe"):

print value

if (value):
prefix = value
else:
prefix = 'TRUE'
print(value)

prefix = value if value else "TRUE"
generate(prefix, number)

except Usage, err:
print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
print >> sys.stderr, "\t for help use --help"
except Usage as err:
print(sys.argv[0].split("/")[-1] + ": " + str(err.msg), file=sys.stderr)
print("\t for help use --help", file=sys.stderr)
return 2


Expand Down
Loading

0 comments on commit 743e446

Please sign in to comment.