2
0
mirror of https://github.com/ComradCollective/Comrad synced 2024-11-05 21:20:51 +00:00
Comrad/komrade/cli/artcode.py

976 lines
19 KiB
Python
Raw Normal View History

2020-09-10 21:32:59 +00:00
ART_TELEPHONE = '''
..--""""----..
.-" ..--""""--.j-.
.-" .-" .--.""--..
2020-09-11 14:35:47 +00:00
.-" .-" ..--"-. \\/ ;
2020-09-10 21:32:59 +00:00
.-" .-"_.--..--"" ..--' "-. :
2020-09-11 14:35:47 +00:00
.' .' / `. \\..--"" __ _ \\ ;
:.__.-" \\ / .' ( )"-. Y
; ;: ( ) ( ). \\
.': /:: : \\ \\
.'.-"\\._ _.-" ; ; ( ) .-. ( ) \\
" `.""" .j" : : \\ ; ; \\
bug /"""""/ ; ( ) "" :.( ) \\
/\\ / : \\ \\`.: _ \\
: `. / ; `( ) (\\/ :" \\ \\
\\ `. : "-.(_)_.' t-' ;
\\ `. ; ..--":
2020-09-10 21:32:59 +00:00
`. `. : ..--"" :
`. "-. ; ..--"" ;
`. "-.:_..--"" ..--"
`. : ..--""
"-. : ..--""
"-.;_..--""
'''
ART_PHONE_SM1 = """
.----------------.
2020-09-11 14:35:47 +00:00
/ _H______H_ \\@,
\\____/ \\____/ @,
/ \\ `@
2020-09-10 21:32:59 +00:00
| LI LI LI | ,@
| LI LI LI | ,@'
| LI LI LI | ,@'
| LI LI LI |@@'
2020-09-12 13:11:39 +00:00
\\ /'
2020-09-10 21:32:59 +00:00
`----------'
"""
ART_ROTARY2="""
_______________
2020-09-11 14:35:47 +00:00
/ \\
2020-09-10 21:32:59 +00:00
| .---------. |@
'---' .-----. '---'@
2020-09-11 14:35:47 +00:00
.' /6 5_4 3\\ '. @
| |7 /...\\ 2| | @
| |8 \\___/ 1| | @
| \\_9_0_)\\/ | @@
2020-09-10 21:32:59 +00:00
/==|_____________|@@@@
H-------------------@@
H ) || || ( @@
2020-09-11 14:35:47 +00:00
H / || || \\ @
2020-09-10 21:32:59 +00:00
H |----''---''----|
=/ |_______________|
"""
ART_KEY = """
8 8 8 8 ,ooo.
2020-09-12 07:55:23 +00:00
8a8 8a8 oP b
2020-09-10 21:32:59 +00:00
d888a888zzzzzzzzzzzzzzzzzzzz8 8b
2020-09-12 07:55:23 +00:00
`""^""' o___oP'
2020-09-10 21:32:59 +00:00
"""
ART_OLDPHONE = """
__
2020-09-11 14:35:47 +00:00
/` _`\\
2020-09-10 21:32:59 +00:00
| (_()| .-.
2020-09-11 14:35:47 +00:00
\\_ _/_/ \\
2020-09-10 21:32:59 +00:00
||=[_] |
|| | | |
2020-09-11 14:35:47 +00:00
||/ \\ |
2020-09-10 21:32:59 +00:00
||`---' /
.--'||-.___.'
/` .-||-.
2020-09-11 14:35:47 +00:00
'-/`.____.`\\
2020-09-10 21:32:59 +00:00
jgs '.______.'
"""
ART_OLDPHONE2="""
_|~|/|
( | | |
2020-09-11 14:35:47 +00:00
/_|_|\\|
2020-09-10 21:32:59 +00:00
| |
| |~|
| | |
| | |
| |-|
2020-09-11 14:35:47 +00:00
| | \\
2020-09-10 21:32:59 +00:00
| |__|
|_|_
/ ~-_
/ ~-_
|___________|
"""
ART_ROTARY = """
_...----..._
,-' ,-. `-.
,' ,-. ( 4 ) ,-. `.
,' ( 5 ) `-' ( 3 ) `.
2020-09-11 14:35:47 +00:00
/ ,-. `-',-'' ``-.`-' ,-. \\
/ ( 6 ) ,' `. ( 2 ) \\
: `-' / FEUER \\ `-' :
2020-09-10 21:32:59 +00:00
| ,-. : ________ : ,-. |
|( 7 ) | |________| | ( 1 )|
| `-' : ; `-' |
2020-09-11 14:35:47 +00:00
: ,-. \\ NOTRUF / ;
\\ ( 8 ) `. ,'(`. /
\\ `-' ,-.`-..__..-' \\ `-./
`. ( 9 ) ,-. \\ ,'
2020-09-10 21:32:59 +00:00
`. `-' ( 0 ) ,'`
`-._ `-' _.-'
```----''' SSt
"""
ART_PHONE_DIAGRAM = """
________
.' / / )
/ /##/ /|
/ `--' / |
/__ __ __ / |
//_//_//_// / __
2020-09-11 14:35:47 +00:00
//_//_//_// / \\`.___ Listening end
2020-09-10 21:32:59 +00:00
//_//_//_// /
//_//_//_// /__
2020-09-11 14:35:47 +00:00
/ / / \\`.___ Buttons
2020-09-10 21:32:59 +00:00
/ .-. / /
/ /#/ / /
/ `-' / /__
2020-09-11 14:35:47 +00:00
/ .====. / / \\`.___ Speaking end
2020-09-10 21:32:59 +00:00
|`--------' /
2020-09-11 14:35:47 +00:00
\\ , .'__
`-//----' \\`.___ Disconnect button
2020-09-10 21:32:59 +00:00
//
"""
ART_OLDPHONE3 = """
__ _
.: .' '.
2020-09-11 14:35:47 +00:00
/: / \\_
;: ; ,-'/`:\\
2020-09-10 21:32:59 +00:00
|: | | |():|
2020-09-11 14:35:47 +00:00
;: ; '-.\\_:/
\\: \\ /`
2020-09-10 21:32:59 +00:00
':_'._.'
||
2020-09-11 14:35:47 +00:00
/__\\
2020-09-10 21:32:59 +00:00
.---. {====}
.' _,"-,__|:: |
/ ((O)=;--.:: |
; `|: | |:: |
| |: | |:: |
| |: | |:: |
| |: | |:: |
| |: | |:: |
| |: | |:: |
2020-09-11 14:35:47 +00:00
| /:'__\\ |:: |
2020-09-10 21:32:59 +00:00
| [______]|:: |
| `----` |:: |__
| _.--|:: | ''--._
; .' __{====}__ '.
2020-09-11 14:35:47 +00:00
\\ .'_.-'._ `""` _.'-._ '.
'--'/` `''''` `\\ '.__
2020-09-10 21:32:59 +00:00
jgs '._ _.'
`""--......--""`
"""
ART_OLDPHONE4 = """
__
2020-09-11 14:35:47 +00:00
/` _`\\
2020-09-10 21:32:59 +00:00
| (_()| .-.
2020-09-11 14:35:47 +00:00
\\_ _/_/ \\
2020-09-10 21:32:59 +00:00
||=[_] |
|| | | |
2020-09-11 14:35:47 +00:00
||/ \\ |
2020-09-10 21:32:59 +00:00
||`---' /
.--'||-.___.'
/` .-||-.
2020-09-11 14:35:47 +00:00
'-/`.____.`\\
'.______.'
2020-09-10 21:32:59 +00:00
"""
2020-09-11 14:35:47 +00:00
# by jgs
2020-09-10 21:32:59 +00:00
ART_PAYPHONE = """
_________________
2020-09-11 14:35:47 +00:00
/ __ \\
2020-09-10 21:32:59 +00:00
| (__) |
| |
| .-----. .--. |
2020-09-11 14:35:47 +00:00
| | | / \\ |
| '-----' \\ / |
2020-09-10 21:32:59 +00:00
| | | |
| LI LI LI | | |
| LI LI LI | | |Oo
| LI LI LI | | |`Oo
| LI LI LI | | | Oo
| | | | Oo
2020-09-11 14:35:47 +00:00
| .------. / \\ | oO
| | | \\ / | Oo
2020-09-10 21:32:59 +00:00
| '------' '-oO | oO
| .---Oo | Oo
| || ||`Oo oO
| |'--'| | OoO
| '----' |
2020-09-11 14:35:47 +00:00
jgs \\_________________/
"""
ART_HAMMER = """
,
/( ___________
| >:===========`
)(
""
"""
ART_KEY_PAIR = """
__
/o \\_____
\__/-="="`
__
/ o\\
\_ /
<|
<|
<|
`
"""
ART_KEY_PAIR2 = """
__
/o \\_____
\__/-="="`
__ (public)
/ o\\
\_ /
<|
<|
<| (private)
"""
ART_KEY_PAIR2A = """
__
/o \\_____
\__/-="="`
__ (1) public key
/ o\\
\_ /
<|
<|
<|
"""
ART_KEY_PAIR2B = """
__
/o \\_____
\__/-="="`
2020-09-12 07:55:23 +00:00
__
2020-09-11 14:35:47 +00:00
/ o\\
\_ /
<|
<|
<| (2) private key
"""
2020-09-12 07:55:23 +00:00
ART_KEY_PAIR2BC = """
__
/o \\_____
\__/-="="`
__________ __ |
| / o\\ |
| \_ / |
| <| |
| <| |
| <| |
|__________|
"""
CUBE = """
+--------------+
/| /|
/ | / |
*--+-----------* |
| | | |
| | | |
| | | |
| +-----------+--+
| / | /
|/ |/
*--------------*
"""
CUBEKEY = """
+--------------+
/| /|
/ | / |
*--+-----------* |
| | / o\\ | |
| | \_ / | |
| | <| | |
| +----<|-----+--+
| / <| | /
|/ |/
*--------------*
"""
ART_KEY_PAIR2Bz = """
__
/o \\_____
\__/-="="`
__ (1) public key
/ o\\
\_ /
<|
<|
<| (2) private key
"""
2020-09-11 17:17:21 +00:00
ART_KEY_PAIR_SPLITTING1 = """
_
/o
\
<
<
<
(2A)
symmetric
encryption
key, from
hashed
passphrase
"""
ART_KEY_PAIR_SPLITTING2 = """
_ __
/o / o\\
\ \_ /
< --(encrypts)--> <|
< <|
< <|
(2A) (2)
symmetric asymmetric
encryption private
key, from key
hashed
passphrase
"""
ART_KEY_PAIR_SPLITTING3 = """
_ __ _
/o / o\\ \\
\ \_ / /
< --(encrypts)--> <| --(into)--> |
< <| |
< <| |
(2A) (2) (2B)
symmetric asymmetric encrypted form
2020-09-12 07:55:23 +00:00
encryption private of (2)
key, from key
2020-09-11 17:17:21 +00:00
hashed
passphrase
"""
2020-09-12 07:55:23 +00:00
ART_KEY_PAIR_SPLITTING4 = """
_ _
/o \\
\ /
< |
< |
< |
(2A) (2B)
symmetric encrypted form
encryption of (2)
key, from
hashed
passphrase
"""
ART_KEY_PAIR_SPLITTING5 = """
_
\\
/
|
|
|
(2B)
encrypted form
of (2)
"""
2020-09-11 14:35:47 +00:00
ART_KEY_PAIR32 = """
__
/o \\_____
\__/-="="`
_ _ (1) public key
/o \\
\ _ /
< |
< |
< | (2B) privkey_encr
(2A) privkey_decr
"""
ART_KEY_PAIR3A2 = """
__
/o \\_____
\__/-="="`
_ _ (1) public key
/o \\
\ _ /
< |
< |
< |
"""
2020-09-11 17:17:21 +00:00
ART_KEY_KEY2A = """ _
/o
\
<
<
<
"""
2020-09-11 14:35:47 +00:00
ART_KEY_PAIR3B2 = """
__
/o \\_____
\__/-="="`
_ _
/o \\
\ _ /
< |
< |
< | (2B) privkey_encr
"""
ART_KEY_PAIR3C2 = """
__
/o \\_____
\__/-="="`
_ _ (1) public key
/o \\
\ _ /
< |
< |
< | (2B) privkey_encr
(2A) privkey_decr
"""
ART_KEY_PAIR3 = """
__
/o \\_____
\__/-="="`
_ _ (1) public key
/o \\
\ _ /
< |
< |
< | (2B) privkey_encr
(2A) privkey_decr
"""
ART_KEY_PAIR4 = """
__
/o \\_____
\__/-="="`
2020-09-12 07:55:23 +00:00
_
\\
_ /
|
|
| (2B) privkey_encr
2020-09-11 14:35:47 +00:00
(2A) privkey_decr
"""
ART_KEY_PAIR4Z = """
__
/o \\_____
\__/-="="`
2020-09-12 07:55:23 +00:00
_
\\
_ /
|
|
|
2020-09-11 14:35:47 +00:00
(2A) privkey_decr
"""
ART_KEY_PAIR4D = """
2020-09-12 07:55:23 +00:00
_
\\
_ /
|
|
| (2B) privkey_encr
2020-09-11 14:35:47 +00:00
(2A) privkey_decr
"""
ART_KEY_PAIR4C = """
2020-09-12 07:55:23 +00:00
_
\\
_ /
|
|
|
2020-09-11 14:35:47 +00:00
(2A) privkey_decr
"""
2020-09-12 07:55:23 +00:00
ART_KEY_PAIR4B = """ _
\\
_ /
|
|
|
2020-09-11 14:35:47 +00:00
"""
ART_KEY_PAIR31A = """
__
/o \\_____
\__/-="="`
(1) public key"""
ART_KEY_PAIR3A = """
__
/o \\_____
\__/-="="`"""
ART_KEY_PAIR3B = """ _ _
/o \\
\ _ /
< |
< |
< |
(2A) (2B) encrypted
encryption form of (2)
key for (2B)
"""
ART_KEY_PAIR5 = """
__
/o \\_____
\__/-="="`
(1) public key
_ _
/o \\
\ _ /
< |
< |
< |
(2A) (2B) encrypted
encryption form of (2)
key for (2B)
"""
ART_KEY_PAIR4Z1 = """
__
/o \\_____
\__/-="="`
(1) public key
2020-09-12 07:55:23 +00:00
_
\\
_ /
|
|
|
2020-09-11 14:35:47 +00:00
(2B) encrypted
form of (2)
"""
2020-09-11 17:17:21 +00:00
ART_KEY_PAIR4ZZ = """
__
/o \\_____
\__/-="="`
2020-09-12 07:55:23 +00:00
_
\\
_ /
|
|
|
2020-09-11 17:17:21 +00:00
"""
2020-09-11 14:35:47 +00:00
ART_KEY_PAIR4Z2 = """
__
/o \\_____
\__/-="="`
(1) public key
2020-09-12 07:55:23 +00:00
2020-09-11 14:35:47 +00:00
"""
# """
ART_KEY_PAIR4Z3 = """
__
/o \\_____
\__/-="="`
2020-09-12 07:55:23 +00:00
(1) public key
2020-09-11 14:35:47 +00:00
"""
ART_KEY_PAIR4Z3 = """
__
/o \\_____
\__/-="="`
2020-09-12 07:55:23 +00:00
(1) public key
2020-09-11 14:35:47 +00:00
"""
ART_KEY_PAIR4Z42 = """
2020-09-12 07:55:23 +00:00
2020-09-11 14:35:47 +00:00
"""
ART_KEY_PAIR4Z4B = """
2020-09-12 07:55:23 +00:00
2020-09-11 14:35:47 +00:00
__
/ o\\
\_ /
<|
<|
<|
"""
ART_KEY_PAIR4Z4 = """
2020-09-12 07:55:23 +00:00
2020-09-11 14:35:47 +00:00
__
/ o\\
\_ /
<|
<|
<|
"""
2020-09-12 07:55:23 +00:00
ART_KEY_PAIR3BB = """ _
\\
_ /
|
|
|
2020-09-11 14:35:47 +00:00
(2A) (2B) encrypted
encryption form of (2)
key for (2B)
"""
ART_KEY_PAIR3AA = """ _ _
/o \\
\ _ /
< |
< |
< |
2020-09-10 21:32:59 +00:00
"""
2020-09-11 14:35:47 +00:00
ART_KEY_PAIR_SEP = """
__
/o \\_____
\__/-="="`
__
/ o\\
\_ /
<|
<|
<|
`
"""
ART_KEY_CHAIN = """
___________ @ @
/ (@\\ @
\___________/ _@
@ _/@ \\_____
@/ \__/-="="`
\_ /
<|
<|
<|
`
"""
ART_FROG_BLENDER ="""
___
_______|___|______
__|__________________|
\ ]________________[ `---.
`. ___ L
| _ | L |
| .'_`--.___ __ | | |
|( 'o` - .`.'_ ) | F F
| `-._ `_`./_ | / /
J '/\\ ( .'/ )F.' /
L ,__//`---'`-'_/J .'
J /-' '/ F.'
L ' J'
J `.`-. .-'.' F
L `.-'.-' J
|__(__(___)__|
F J
J L
|______________|
"""
2020-09-10 21:32:59 +00:00
####
# code
###
from PIL import Image
2020-09-12 07:55:23 +00:00
ASCII_CHARS = [ '#', ' ', '%', '.', 'S', '+', '.', '*', ':', ',', '@']
2020-09-10 21:32:59 +00:00
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=100):
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)]
2020-09-11 14:35:47 +00:00
return "\\n".join(image_ascii)
2020-09-10 21:32:59 +00:00
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)