diff --git a/docs/operator-2262c4d3b4e9c598cfd1e73b028756ac.jpg b/docs/operator-2262c4d3b4e9c598cfd1e73b028756ac.jpg new file mode 100644 index 0000000..d5c91e2 Binary files /dev/null and b/docs/operator-2262c4d3b4e9c598cfd1e73b028756ac.jpg differ diff --git a/komrade/__init__.py b/komrade/__init__.py index b4485fb..4df33fa 100644 --- a/komrade/__init__.py +++ b/komrade/__init__.py @@ -1,8 +1,7 @@ # basic config -from .art import * from .constants import * from .utils import * - +from .cli.artcode import * # common python imports import os,sys diff --git a/komrade/art.py b/komrade/art.py index 82faad6..590348b 100644 --- a/komrade/art.py +++ b/komrade/art.py @@ -23,6 +23,35 @@ ART_TELEPHONE = ''' "-.;_..--"" ''' +ART_PHONE_SM1 = """ + .----------------. + / _H______H_ \@, + \____/ \____/ @, + / \ `@ + | LI LI LI | ,@ + | LI LI LI | ,@' + | LI LI LI | ,@' + | LI LI LI |@@' +jgs \ /' + `----------' +""" + +ART_ROTARY2=""" + _______________ + / \ + | .---------. |@ + '---' .-----. '---'@ + .' /6 5_4 3\ '. @ + | |7 /...\ 2| | @ + | |8 \___/ 1| | @ + | \_9_0_)\/ | @@ + /==|_____________|@@@@ + H-------------------@@ + H ) || || ( @@ + H / || || \ @ + H |----''---''----| +=/ |_______________| +""" ART_KEY = """ @@ -182,4 +211,75 @@ ART_PAYPHONE = """ | |'--'| | OoO | '----' | jgs \_________________/ -""" \ No newline at end of file +""" + + + + + + + + + + +#### +# code +### +from PIL import Image +ASCII_CHARS = [ '#', '?', '%', '.', 'S', '+', '.', '*', ':', ',', '@'] + +def scale_image(image, new_width=100): + """Resizes an image preserving the aspect ratio. + """ + (original_width, original_height) = image.size + aspect_ratio = original_height/float(original_width) + new_height = int(aspect_ratio * new_width) + + new_image = image.resize((new_width, new_height)) + return new_image + +def convert_to_grayscale(image): + return image.convert('L') + +def map_pixels_to_ascii_chars(image, range_width=25): + """Maps each pixel to an ascii char based on the range + in which it lies. + + 0-255 is divided into 11 ranges of 25 pixels each. + """ + + pixels_in_image = list(image.getdata()) + pixels_to_chars = [ASCII_CHARS[pixel_value//range_width] for pixel_value in + pixels_in_image] + + return "".join(pixels_to_chars) + +def convert_image_to_ascii(image, new_width=50): + image = scale_image(image) + image = convert_to_grayscale(image) + + pixels_to_chars = map_pixels_to_ascii_chars(image) + len_pixels_to_chars = len(pixels_to_chars) + + image_ascii = [pixels_to_chars[index: index + new_width] for index in + range(0, len_pixels_to_chars, new_width)] + + return "\n".join(image_ascii) + +def handle_image_conversion(image_filepath): + image = None + try: + image = Image.open(image_filepath) + except Exception as e: + # print "Unable to open image file {image_filepath}.".format(image_filepath=image_filepath) + # print e + return + + image_ascii = convert_image_to_ascii(image) + print(image_ascii) + +if __name__=='__main__': + import sys + + image_file_path = sys.argv[1] + handle_image_conversion(image_file_path) \ No newline at end of file diff --git a/komrade/backend/keymaker.py b/komrade/backend/keymaker.py index 21e17c8..2760e6d 100644 --- a/komrade/backend/keymaker.py +++ b/komrade/backend/keymaker.py @@ -3,7 +3,7 @@ from komrade import * from komrade.backend.crypt import * from abc import ABC, abstractmethod -class KomradeKey(ABC): +class KomradeKey(ABC,Logger): @abstractmethod def encrypt(self,msg,**kwargs): pass @abstractmethod @@ -31,14 +31,23 @@ class KomradeSymmetricKey(KomradeKey): return self.cell.encrypt(msg,**kwargs) def decrypt(self,msg,**kwargs): return self.cell.decrypt(msg,**kwargs) - + +def getpass_status(passphrase=None): + while not passphrase: + passphrase1 = getpass(f'@Keymaker: What is a *memorable* pass word or phrase? Do not write it down.\n@{name}: ') + passphrase2 = getpass(f'@Keymaker: Could you repeat that?') + if passphrase1!=passphrase2: + self.status('@Keymaker: Those passwords didn\'t match. Please try again.',clear=False,pause=False) + else: + return passphrase1 + class KomradeSymmetricKeyWithPassphrase(KomradeSymmetricKey): def __init__(self,passphrase=DEBUG_DEFAULT_PASSPHRASE, why=WHY_MSG): self.passphrase=passphrase if not self.passphrase: - self.passphrase=getpass.getpass(why) + self.passphrase=getpass_status if SHOW_LOG else getpass.getpass(why) #return self.passphrase @property def data(self): return KEY_TYPE_SYMMETRIC_WITH_PASSPHRASE.encode('utf-8') @@ -70,20 +79,36 @@ class KomradeAsymmetricKey(KomradeKey): def data(self): return self.key class KomradeAsymmetricPublicKey(KomradeAsymmetricKey): + def __init__(self,pubkey,privkey=None): + self.pubkey=pubkey + self.privkey=privkey @property def key(self): return self.pubkey @property def data(self): return self.pubkey - def __repr__(self): return f'''[Asymmetric Public Key] ({self.discreet})''' + def __repr__(self): return f'''[Asymmetric Public Key] ({self.data_b64.decode()})''' class KomradeAsymmetricPrivateKey(KomradeAsymmetricKey): + def __init__(self,privkey,pubkey=None): + self.pubkey=pubkey + self.privkey=privkey @property def data(self): return self.privkey @property def key(self): return self.privkey def __repr__(self): return f'''[Asymmetric Private Key] ({self.discreet})''' -def make_key_discreet(data,len_start=10,len_end=10,ellipsis='.',show_len=True): +def make_key_discreet(data,chance_bowdlerize=0.5): + import random + + if not data: return '?' + if not isBase64(data): data=b64encode(data) + key=data.decode() + + return ''.join((k if random.random()