Study Record

[암호 프로그래밍] 인코딩/디코딩 프로그램 본문

암호/프로그래밍

[암호 프로그래밍] 인코딩/디코딩 프로그램

초코초코초코 2021. 12. 7. 11:52
728x90

※ 사전 준비

Linux 에 hURL 설치 - https://laustudy.tistory.com/109

 

인코딩 디코딩 쉘 프로그램 만들기

# vi /python/enc.sh # vi /python/dec.sh
#!/bin/bash
 
if [ $# -le 0 ] ; then
echo "$0 <string>"
exit 1
fi
 
echo "========== URL encoding ==========="
hURL -U "$@"
echo; echo
 
echo "========== BASE64 encoding ============"
hURL -B "$@"
echo; echo
 
echo "========== HTML encoding ============="
hURL -H "$@"
echo; echo
#!/bin/bash
 
if [ $# -le 0 ] ; then
echo "$0 <string>"
exit 1
fi
 
echo "========== URL encoding ==========="
hURL -u "$@"
echo; echo
 
echo "========== BASE64 encoding ============"
hURL -b "$@"
echo; echo
 
echo "========== HTML encoding ============="
hURL -h "$@"
echo; echo

 

인코딩 디코딩 파이썬 프로그램

import os


def menu():
    print()
    print("="*13)
    print(" 1) Encoding    2) Decoding    3) Quit")
    print("="*13)


def main():
    while True:
        menu()
        num = input("Enter your choice? (1\\2\\3\\): ")

        if num == '1':
            str = input("Input your string(ex: \"string\"): ")
            if str == "":
                print("[ ERROR ] Must be string. (ex: hello world)")
            else:
                if os.system("/python/enc.sh " + str) != 0:
                    print("[ ERROR ] enc error")
            pass
        elif num == '2':
            str = input("Input your string(ex: \"string\"): ")
            if str == "":
                print("[ ERROR ] Must be string. (ex: hello world)")
            else:
                if os.system("/python/dec.sh " + str) != 0:
                    print("[ ERROR ] dec error")
            pass
        elif num == '3':
            break
        else:
            print("[ WARN ] Wrong Choice: You must be 1|2|3")


if __name__ == '__main__':
    main()
728x90