This program is to convert string data into trinary digit, as follow:
Trinary Digit 9 3 1 0 0 0 = 0 <space> 0 0 1 = 1 a 0 0 2 = 2 b 0 1 0 = 3 c 0 1 1 = 4 d 0 1 2 = 5 e 0 2 0 = 6 f 0 2 1 = 7 g 0 2 2 = 8 h 1 0 0 = 9 i 1 0 1 = 10 j 1 0 2 = 11 k 1 1 0 = 12 l 1 1 1 = 13 m 1 1 2 = 14 n 1 2 0 = 15 o 1 2 1 = 16 p 1 2 2 = 17 q 2 0 0 = 18 r 2 0 1 = 19 s 2 0 2 = 20 t 2 1 0 = 21 u 2 1 1 = 22 v 2 1 2 = 23 w 2 2 0 = 24 x 2 2 1 = 25 y 2 2 2 = 26 z
The codes are as follow:
#! /usr/local/bin/python3.2
### This program converts data into trinary codes ###
def algorithm(x):
if x == ' ':
print('000')
elif x == 'a' or x =='A':
print('001')
elif x == 'b' or x =='B':
print('002')
elif x == 'c' or x == 'C':
print('010')
elif x == 'd' or x == 'D':
print('011')
elif x == 'e' or x == 'E':
print('012')
elif x == 'f' or x == 'F':
print('020')
elif x == 'g' or x == 'G':
print('021')
elif x == 'h' or x == 'H':
print('022')
elif x == 'i' or x == 'I':
print('100')
elif x == 'j' or x == 'J':
print('101')
elif x == 'k' or x == 'K':
print('102')
elif x == 'l' or x == 'L':
print('110')
elif x == 'm' or x == 'M':
print('111')
elif x == 'n' or x == 'N':
print('112')
elif x == 'o' or x == 'O':
print('120')
elif x == 'p' or x == 'P':
print('121')
elif x == 'q' or x == 'Q':
print('122')
elif x == 'r' or x == 'R':
print('200')
elif x == 's' or x == 'S':
print('201')
elif x == 't' or x == 'T':
print('202')
elif x == 'u' or x == 'U':
print('210')
elif x == 'w' or x == 'W':
print('212')
elif x == 'x' or x == 'X':
print('220')
elif x == 'y' or x == 'Y':
print('221')
elif x == 'z' and x == 'Z':
print('222')
string = input('\nEnter a string: ')
for eachLetter in string:
algorithm(eachLetter)
I'm seeking ways to simplify the function "algorithm(x)", and also to improve this program into an encryption system~ ^_^


Sign In
Create Account

Back to top









