Ejemplo n.º 1
0
 def str(self, cfg):
     func = cfg[self.subname('func')]
     if func == FUNC_ROOT:
         ans = '%s.root()' % self.name
     elif func == FUNC_INLINE:
         return '' #'%s.inline()' % self.name
     else:
         raise ValueError('Unknown func schedule %d' % func)
     
     for i in range(len(self.vars)):
         var = cfg[self.subname('var%d'%i)]
         if var == VAR_SERIAL:
             pass
         elif var in [VAR_VECTORIZE, VAR_UNROLL]:
             ans += '.%s(%s, %d)' % ('vectorize' if var == VAR_VECTORIZE else 'unroll', self.vars[i], cfg[self.subname('var%d_arg0'%i)])
         elif var == VAR_PARALLEL:
             ans += '.parallel(%s)' % (self.vars[i])
         else:
             raise ValueError('Unknown var schedule %d' % var)
     
     transpose = cfg[self.subname('transpose')]
     if transpose > 0:
         #print transpose, self.vars, permutation(self.vars, transpose)
         #assert self.vars == ['x', 'y'], self.vars
         for (a, b) in pairwise_swaps(self.vars, permutation(self.vars, transpose)):
             ans += '.transpose(%s,%s)' % (a, b)
     return ans + ';'
Ejemplo n.º 2
0
def main():
    print("Welcome to Harrison Pickett's Computer Security Assignment 1 solution.")
    print("What encryption algorithm would you like to use?")
    algorithm   = raw_input("[V]igenere, [P]ermutation").lower()
    file_name   = raw_input("Input File Path: ").lower()
    out_file    = raw_input("Output File Path: ").lower()
    key         = raw_input("Key: ").lower()
    en_de_code  = raw_input("[E]ncoding or [D]ecoding: ").lower()
    spaces      = raw_input("[K]eeping or [R]emoving Spaces: ").lower()
    
    if ((en_de_code == "d") or (en_de_code == "decoding")):
        decode = True
        en_de_code = "Decoding"
    else:
        decode = False
        en_de_code = "Encoding"
        
    if ((spaces == "k") or (spaces == "keeping")):
        keep_spaces = True
        spaces = "Keep"
    else:
        keep_spaces = False
        spaces = "Omit"

    if (file_name == ""):
        file_name = "./input.txt"

    if (out_file == ""):
        out_file = "./output.txt"
        
    str_text    = read_file(file_name)    
    
    if ((algorithm == "v") or (algorithm == "vigenere")):
        algorithm = "Vigenere"
        r_val = vigenere(key, str_text, decode, keep_spaces)
    elif ((algorithm == "p") or (algorithm == "permutation")):
        algorithm = "Permutation"
        key = key_to_list(key)
        r_val = permutation(key, str_text, decode, keep_spaces)
        
    write_file(out_file, [
        "Algorithm: ", algorithm,
        "Key: ", str(key),
        en_de_code, spaces,
        "Generated Text: ", r_val,
        "Original Text: ", str_text])
    
    return
Ejemplo n.º 3
0
def largestNthPendigital(n):
     p_list = map(lambda n: int(n), permutation(str(n)))
     for n in p_list:
	 if isprime(n):
	     return n