Best Python code snippet using pyresttest_python
signature.py
Source:signature.py
...34 while not is_next_prime:35 sk_q = sk_q + 236 is_next_prime = number.isPrime(sk_q)37 return keypair_to_json(sk_p, sk_q, pk)38def get_generator(p, q):39 n = p*q40 found = False41 while not found:42 g = randrange(2, n)43 found = number.GCD(g, n) == 1 and pow(g, 4, n) != 144 return g 45# Generate signature accumulator and groups46# Output: Accumulator base, Linkable tag, N_sig, phiN_sig, p_sig, q_sig47def gen_sig_param():48 '''49 p_sig = number.getStrongPrime(lamb//2) # might be safe prime, but it is too slow50 q_sig = number.getStrongPrime(lamb//2) # might be safe prime, but it is too slow51 N_sig = p_sig * q_sig52 phiN_sig = (p_sig-1) * (q_sig-1)53 '''54 u = get_generator(p_sig, q_sig) # Accum base55 g_theta = get_generator(p_sig, q_sig) # linkable tag base56 return u, g_theta, N_sig, phiN_sig, p_sig, q_sig57def gen_accum_voters(accumBase, voters):58 power = 159 for voter in voters:60 power = (power*voter)%phiN_sig61 return pow(accumBase, power, N_sig)62# Sign a message63# Input: list_of_pks, Key pair(sk_p, sk_q, pk), Message(int tuple (c1, c2)), parameters(u, g_theta)64# Output: Signature(str)65def sign_ballot(list_of_pks, key_pair, m, param):66 sk_p, sk_q, pk = key_pair67 u, g_theta = param68 g = get_generator(p_sig, q_sig) # some generator for signature69 h = get_generator(p_sig, q_sig) # some generator for signature70 s = get_generator(p_sig, q_sig) # some generator for signature71 t = get_generator(p_sig, q_sig) # some generator for signature72 y = get_generator(p_sig, q_sig) # some generator for signature73 y_hat = pow(g_theta, sk_p+sk_q, N_sig)74 w = u # witness75 product_of_other_pk = 176 for other_pk in list_of_pks:77 w = pow(w, other_pk, N_sig)78 product_of_other_pk = (product_of_other_pk * other_pk) % phiN_sig79 v = pow(w, pk, N_sig) # all public key accumulated80 r = randrange(2, phiN_sig) # a secret random seed need to be 81 T1 = pow(g, r, N_sig)82 T2 = (pow(g, pk, N_sig) * pow(h, r, N_sig)) % N_sig83 T3 = (pow(g, sk_q, N_sig) * pow(s, r, N_sig)) % N_sig84 T4 = (w * pow(y, r, N_sig)) % N_sig85 T5 = (pow(g, sk_p, N_sig) * pow(t, r, N_sig)) % N_sig86 T6 = pow(T1, pk, N_sig)...
generator.py
Source:generator.py
1from node import *2def get_generator(node):3 if node.t == Node.BLOCK:4 return GeneratorBlock(node)5 elif node.t == Node.IDENTIFIER:6 return GeneratorIdentifier(node)7 elif node.t == Node.ARGS:8 return GeneratorArgs(node)9 elif node.t == Node.FUNC:10 return GeneratorFunc(node)11 elif node.t == Node.FUNC_CALL:12 return GeneratorFuncCall(node)13 elif node.t == Node.OP:14 return GeneratorOp(node)15 elif node.t == Node.IF:16 return GeneratorIf(node)17 elif node.t == Node.CONST_LITERAL:18 return GeneratorConstLiteral(node)19 elif node.t == Node.INDEXING:20 return GeneratorIndexing(node)21 elif node.t == Node.OBJ_LITERAL:22 return GeneratorObjectLiteral(node)23 elif node.t == Node.FOR:24 return GeneratorFor(node)25 elif node.t == Node.WHILE:26 return GeneratorWhile(node)27 elif node.t == Node.REPEAT:28 return GeneratorRepeat(node)29class Generator(object):30 def __init__(self, node):31 self.node = node32class GeneratorBlock(Generator):33 def __init__(self, node):34 Generator.__init__(self, node)35 def generate(self):36 out = ''37 for child in self.node.children:38 if child is not None:39 out += get_generator(child).generate()40 if child.t != Node.IF and child.t != Node.FUNC and child.t != Node.WHILE and child.t != Node.REPEAT and child.t != Node.FOR:41 out += ';\n'42 return out43class GeneratorIdentifier(Generator):44 def __init__(self, node):45 Generator.__init__(self, node)46 def generate(self):47 return self.node.name48class GeneratorArgs(Generator):49 def __init__(self, node):50 Generator.__init__(self, node)51 def generate(self):52 out = ''53 for arg in self.node.children:54 out += get_generator(arg).generate() + ','55 if self.node.children:56 out = out[:-1] # remove last comma57 return out58class GeneratorFunc(Generator):59 def __init__(self, node):60 Generator.__init__(self, node)61 def generate(self):62 return 'function ' + GeneratorIdentifier(self.node.children[0]).generate() + '( ' + GeneratorArgs(self.node.children[1]).generate() + ') {\n' + GeneratorBlock(self.node.children[2]).generate() + '}\n'63class GeneratorFuncCall(Generator):64 def __init__(self, node):65 Generator.__init__(self, node)66 def generate(self):67 str = GeneratorIdentifier(self.node.children[0]).generate() + '( ' + GeneratorArgs(self.node.children[1]).generate() + ')'68 return str69class GeneratorOp(Generator):70 def __init__(self, node):71 Generator.__init__(self, node)72 def generate(self):73 if self.node.n == -1:74 out = self.node.op75 if self.node.op == 'new':76 out += ' '77 out += get_generator(self.node.children[0]).generate()78 elif self.node.n == 1:79 out = get_generator(self.node.children[0]).generate() + self.node.op80 elif self.node.n == 2:81 out = get_generator(self.node.children[0]).generate() + ' ' + self.node.op + ' ' + get_generator(self.node.children[1]).generate()82 return out83class GeneratorIf(Generator):84 def __init__(self, node, ifelse=False):85 Generator.__init__(self, node)86 self.ifelse = ifelse87 def generate(self):88 out = 'if ( ' + get_generator(self.node.children[0]).generate() + ' ) {\n' + GeneratorBlock(self.node.children[1]).generate() + '}\n'89 if self.ifelse:90 out.insert(0, 'else ')91 if len(self.node.children) > 2:92 for i in range(2, len(self.node.children), 1):93 if self.node.children[i] == Node.IF:94 GeneratorIf(self.node.children[i], True)95 else:96 out += 'else {\n' + GeneratorBlock(self.node.children[i]).generate() + '}\n'97 return out98class GeneratorConstLiteral(Generator):99 def __init__(self, node):100 Generator.__init__(self, node)101 def generate(self):102 return self.node.literal103class GeneratorIndexing(Generator):104 def __init__(self, node):105 Generator.__init__(self, node)106 def generate(self):107 return GeneratorIdentifier(self.node.children[0]).generate() + '[' + get_generator(self.node.children[1]).generate() + ']'108class GeneratorObjectLiteral(Generator):109 def __init__(self, node):110 Generator.__init__(self, node)111 def generate(self):112 out = '{ \n'113 for child in self.node.children:114 out += GeneratorIdentifier(child.children[0]).generate() + ': ' + get_generator(child.children[1]).generate() + ',\n'115 if child:116 out = out[:-2] # remove last comma117 out += '}'118 return out119class GeneratorFor(Generator):120 def __init__(self, node):121 Generator.__init__(self, node)122 def generate(self):123 out = 'for ('124 if self.node.children[0] is not None:125 out += get_generator(self.node.children[0]).generate()126 out += ';'127 if self.node.children[1] is not None:128 out += get_generator(self.node.children[1]).generate()129 out += ';'130 if self.node.children[2] is not None:131 out += get_generator(self.node.children[2]).generate()132 out += ') {\n'133 out += GeneratorBlock(self.node.children[3]).generate()134 out += '}\n'135 return out136class GeneratorWhile(Generator):137 def __init__(self, node):138 Generator.__init__(self, node)139 def generate(self):140 out = 'while (' + get_generator(self.node.children[0]).generate() + ') {\n'141 out += GeneratorBlock(self.node.children[1]).generate()142 out += '}\n'143 return out144class GeneratorRepeat(Generator):145 def __init__(self, node):146 Generator.__init__(self, node)147 def generate(self):148 out = 'do {\n'149 out += GeneratorBlock(self.node.children[1]).generate()150 out += 'if (' + get_generator(self.node.children[0]).generate() + ') break;\n'151 out += '}'152 out += 'while (true);\n'...
question_52.py
Source:question_52.py
1# coding: utf-82def get_generator():3 for v in range(1, 6):4 yield v5def display_number():6 gen = get_generator()7 for v in gen:8 print(v)9def sum_number():10 val = 011 gen = get_generator()12 for v in gen:13 val += v14 15 return val16def multiply_number():17 val = 118 gen = get_generator()19 for v in gen:20 val *= v21 return val22display_number()23print(sum_number())...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!