Exemple #1
0
 def record_to_clipboard(self,
                         record_index=None,
                         record_key=None,
                         username=False):
     if record_index is not None:
         record_index = int(record_index)
     if self.master_pass is None:
         self.master_pass = self.get_master_password()
     if record_key is not None:
         for i, record in enumerate(self.data):
             if record['key'] == record_key:
                 record_index = i
         if record_index is None:
             raise Exception('No record with given key')
     if username:
         clip_data = self.data[record_index]['username']
     else:
         clip_data = str(
             decrypt(self.master_pass,
                     self.data[record_index]['password']).decode('cp1252'))
     os.system('echo "' + clip_data + '" | xclip -r -selection clipboard')
Exemple #2
0
 def print(self,
           decrypt_password=False,
           record_index=None,
           record_key=None):
     if decrypt_password and self.master_pass is None:
         self.master_pass = self.get_master_password()
     print(colors['red'] + '########### PASSWORDS #########' +
           colors['end'])
     for i, record in enumerate(self.data):
         if record_index is not None and record_index != i:
             continue
         if record_key is not None and record['key'] != record_key:
             continue
         key = ''
         if record['key'] != '':
             key = ' :: ' + record['key']
         print(colors['cyan'] + '#' + str(i) + key + colors['end'])
         print(colors['bold'] + 'username: '******'end'] +
               '{}'.format(record['username']))
         if decrypt_password:
             try:
                 print(colors['green'] + 'password' + colors['end'] +
                       ': {}'.format(
                           decrypt(self.master_pass,
                                   record['password']).decode('cp1252')))
             except UnicodeDecodeError:
                 print(colors['green'] + 'password' + colors['end'] +
                       ': decryption failed')
         else:
             print('password: {}'.format(record['password']))
         if record['website'] != '':
             print(colors['bold'] + 'website' + colors['end'] +
                   ': {}'.format(record['website']))
         if record['description'] != '':
             print(colors['bold'] + 'description' + colors['end'] +
                   ': {}'.format(record['description']))
         print(colors['red'] + '###' + colors['end'])
Exemple #3
0
        parser.error('The deck must contain all unique values of 1-52.')

if args.passphrase:
    passphrase = args.passphrase.upper().replace(' ','')
    for char in passphrase:
        alg.prng(deck, char, iv=True)

if args.encrypt:
    plaintext = args.encrypt.upper()
    encrypted = encoder.encrypt(plaintext, alg, deck, n=5)

    ciphertext = ''
    for index, char in enumerate(encrypted):
        if index % 5 < 4:
            ciphertext += char
        else:
            ciphertext += char + ' '
    print(ciphertext)

elif args.decrypt:
    ciphertext = args.decrypt.replace(' ','')
    decrypted = encoder.decrypt(ciphertext, alg, deck, n=5)

    plaintext = ''
    for char in decrypted:
        plaintext += char
    print(plaintext)

else:
    print('-e|--encrypt or -d|--decrypt is required')
import struct
import encoder
import getpass

a = getpass.getpass(prompt="enter your password")

with open("./secure/password.len", "r") as l:
    thelen = l.readlines()

with open("./secure/password.codes", "rb") as f:
    v = 0
    data = f.read()
    # print(len(data))
    for i in range(len(thelen)):
        # print(v)
        byt = data[v:v + int(thelen[i].strip("\n"))]
        # print(v,int(thelen[i].strip("\n")))
        print(encoder.decrypt(byt, bytes(a, "utf-8")))
        v = int(thelen[i].strip("\n"))
        # print(v)
    def proc(self, my_msg, peer_code, peer_msg):
        self.out_msg = ''
#==============================================================================
# Once logged in, do a few things: get peer listing, connect, search
# And, of course, if you are so bored, just go
# This is event handling instate "S_LOGGEDIN"
#==============================================================================
        if self.state == S_LOGGEDIN:
            # todo: can't deal with multiple lines yet
            if len(my_msg) > 0:
                if my_msg == 'q':
                    self.out_msg += 'See you next time!\n'
                    self.state = S_OFFLINE
                    
                elif my_msg == 'time':
                    mysend(self.s, M_TIME)
                    time_in = myrecv(self.s)
                    self.out_msg += time_in
                            
                elif my_msg == 'who':
                    mysend(self.s, M_LIST)
                    logged_in = myrecv(self.s)
                    self.out_msg += 'Here are all the users in the system:\n'
                    self.out_msg += logged_in
                            
                elif my_msg[0] == 'c':
                    peer = my_msg[1:].strip()
                    if self.connect_to(peer) == True:
                        self.state = S_CHATTING
                        self.out_msg += 'Connect to ' + peer + '. Chat away!\n\n'
                        self.out_msg += '-----------------------------------\n'
                    else:
                        self.out_msg += 'Connection unsuccessful\n'
                        
                elif my_msg[0] == '?':
                    term = my_msg[1:].strip()
                    mysend(self.s, M_SEARCH + term)
                    search_rslt = myrecv(self.s)[1:].strip()
                    if (len(search_rslt)) > 0:
                        self.out_msg += search_rslt + '\n\n'
                    else:
                        self.out_msg += '\'' + term + '\'' + ' not found\n\n'
                        
                elif my_msg[0] == 'p':
                    poem_idx = my_msg[1:].strip()
                    mysend(self.s, M_POEM + poem_idx)
                    poem = myrecv(self.s)[1:].strip()
                    if (len(poem) > 0):
                        self.out_msg += poem + '\n\n'
                    else:
                        self.out_msg += 'Sonnet ' + poem_idx + ' not found\n\n'
                        
                else:
                    self.out_msg += menu
                    
            if len(peer_msg) > 0:
                if peer_code == M_CONNECT:
                    self.peer = peer_msg
                    self.out_msg += 'Request from ' + self.peer + '\n'
                    self.out_msg += 'You are connected with ' + self.peer 
                    self.out_msg += '. Chat away!\n\n'
                    self.out_msg += '------------------------------------\n'
                    #mysend(self.s, "[s]" + "d" * 299939999)
                    self.state = S_CHATTING
                    
#==============================================================================
# Start chatting, 'bye' for quit
# This is event handling instate "S_CHATTING"
#==============================================================================
        elif self.state == S_CHATTING:
            if len(my_msg) > 0:     # My stuff, going out
                if my_msg[:4] == 'load':
                    try:
                        config = open(my_msg[5:]).read()
                        mysend(self.s, M_CONFIG + config)
                    except FileNotFoundError:
                        self.out_msg += "The file %s does not exist." % my_msg[1:]
                elif my_msg == 'start':
                    mysend(self.s, M_START)
                else:
                    mysend(self.s, M_EXCHANGE + "[" + self.me + "] " + my_msg)
                if my_msg == 'bye':
                    self.disconnect()
                    self.state = S_LOGGEDIN
                    self.peer = ''
            if len(peer_msg) > 0:   # Peer's stuff, coming in
                # New peer joins
                if peer_code == M_CONNECT:
                    self.out_msg += "(" + peer_msg + " joined)\n"
                elif peer_code == M_CONFIG:
                    self.out_msg += "<Server: Recieved config data of length %d>" % len(peer_msg[1:])
                elif peer_code == M_START:
                    print("<Server: Starting render.>")
                    num, start, end, config = peer_msg.split("$$")
                    self.prevconfig = json.loads(config)
                    num = int(num)
                    start = int(start)
                    end = int(end)
                    if not self.thread.is_alive():
                        self.thread = threading.Thread(target=dostuff,
                         args=(self.s, config, num, start, end))
                        self.thread.start()
                elif peer_code == M_RESULT:
                    # first, restore parts
                    parts = json.loads(peer_msg)
                    imgparts = [encoder.decrypt(x) for x in parts]
                    # stitch together sections
                    final = stitch(imgparts)
                    self.out_msg += "Recieved results."
                    final.show()
                    final.save('out/' + hashed(self.prevconfig) + ".png")
                else:
                    self.out_msg += peer_msg

            # I got bumped out
            if peer_code == M_DISCONNECT:
                self.state = S_LOGGEDIN

            # Display the menu again
            if self.state == S_LOGGEDIN:
                self.out_msg += menu
#==============================================================================
# invalid state                       
#==============================================================================
        else:
            self.out_msg += 'How did you wind up here??\n'
            print_state(self.state)
            
        return self.out_msg
Exemple #6
0
if args.passphrase:
    passphrase = args.passphrase.upper()
    for char in passphrase:
        alg.mix_deck(deck)
        deck = alg.count_cut(deck, encoder.plist.index(char)+1)

if args.encrypt:
    plaintext = args.encrypt.upper()
    encrypted = encoder.encrypt(plaintext, alg, deck, 5, base)

    ciphertext = ''
    for index, char in enumerate(encrypted):
        if index % 5 < 4:
            ciphertext += char
        else:
            ciphertext += char + ' '
    print(ciphertext)

elif args.decrypt:
    ciphertext = args.decrypt.replace(' ','')
    decrypted = encoder.decrypt(ciphertext, alg, deck, 5, base)

    plaintext = ''
    for char in decrypted:
        plaintext += char
    print(plaintext)

else:
    print('-e|--encrypt or -d|--decrypt is required')