Last active
December 18, 2015 00:29
-
-
Save bigomega/5697382 to your computer and use it in GitHub Desktop.
ND Encryption Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ************************************************** | |
# ND Encription algorithm (nde) | |
# - derived from phonetics of words | |
# - replacing the first two consonent sounds of every word | |
# - works best for tamil words written in english | |
# Authors: | |
# Bharath => Rabhath | |
# Dhinesh => Nidhesh | |
# ************************************************** | |
vowels = "aeiou" | |
pairs = "ng" #add pairs with spaces eg: "ng fr st" | |
print "give words or sentences.\n\"q\" to exit\n" | |
def nde(words): | |
for j in range(len(words)): | |
c1 = "" #consonent-1 | |
c2 = "" #consonent-2 | |
c1end = 0 | |
c2start = 0 | |
c2end = 0 | |
if words[j][0] in vowels: | |
for i in range(len(words[j])): | |
if words[j][i] not in vowels: | |
c1end = c2start = i | |
c1 = words[j][:i] | |
if i+1 < len(words[j]) and (words[j][i+1] == 'h' or words[j][i:(i+2)] in pairs or words[j][i] == words[j][i+1]): | |
c2 = words[j][i:(i+2)] | |
c2end = i+2 | |
else: | |
c2 = words[j][i] | |
c2end = i+1 | |
break | |
else: | |
for i in range(len(words[j])): | |
if c2: | |
break | |
elif c1 and words[j][i] not in vowels and not c2start: | |
c2start = i | |
if i+1 < len(words[j]) and (words[j][i+1] == 'h' or words[j][i:(i+2)] in pairs or words[j][i] == words[j][i+1]): | |
c2 = words[j][i:(i+2)] | |
c2end = i+2 | |
else: | |
c2 = words[j][i] | |
c2end = i+1 | |
elif words[j][i] in vowels: | |
c1end = i | |
c1 = words[j][:i] | |
if not c1: | |
continue | |
if c2start and not c2: | |
c2end = len(words[j]) | |
c2 = words[j][c2start:] | |
words[j] = c2 + words[j][c1end:c2start] + c1 + words[j][c2end:] | |
words[0] = words[0].title() | |
return ' '.join(words) | |
if __name__ == "__main__": | |
while True: | |
plain = raw_input() | |
if plain == "q": break | |
print '> ' + nde(plain.lower().split(' ')) + '\n' | |
print "\nFunny algorithm right? xD i know... :P\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment