#!/usr/bin/evn python
#-*- coding:utf-8 -*-
'''
    coded by 0zzy
    https://0zzy.5v.pl
    morse code scrambler
                        '''
import os
import sys
#download morse.py
import morse
def help(): #command line 
    print('python scypher.py command txt\n')
    print('command:\n'+'-e -> encrypt\n'+'-d -> decypt')
    print('CTRL+Q -> close')

def encrypt(filename): #encrypt file
    print('ENCRYPTION RUNNING....')
    char=morse.letter
    f=open("succes.txt","w")
    with open(filename,'r') as text:
        line=text.read()
        num_char=len(line)
        all_letters=tuple(line)
        #counts characters in a file
        for i in range(0,num_char):
            for c,v in char.items():
                #checks if the letters are in morse
                if all_letters[i] in c:
                    print(all_letters[i], end=" ")
                    print(v, end=" ")
                    f.write(v)
    f.close()
    print('\nENCRYPION COMPLETE...')

if __name__=='__main__':
    #clear or cls
    os.system("clear")
    try:
        #parameters app
        app=sys.argv[0]
        cmd=sys.argv[1]
        data=sys.argv[2]
        if cmd=="-e":
            encrypt(data)
        elif cmd=="-d":
            print("deszyfruj")
            #here, think for yourself how to decrypt it
        else:
            help()
    except Exception as exception:
        err=tuple(str(exception))
        word=err[0]+err[1]+err[2]+err[3]
        if word=="list":
            help()
        else:
            print('Error:::'+str(exception))
            
        
        
        
    
    
