Using python programming langauge. PROBLEM 4: ·Write a function named infer-lang
ID: 3733512 • Letter: U
Question
Using python programming langauge.
PROBLEM 4: ·Write a function named infer-language (encrypted-textfile) that takes as parameters the name of an encrypted text file and return the language of the text in the encrypted file. For this task you may assume that only the following languages are possible: zulu, english and dutch. . Write a function named caesar.decrypt3(encrypted.textfile) that takes as parameter the name of an encrypted text file, and return a string that is the caesar-decrypted version of the text fileExplanation / Answer
CAESER_DECRYPT()
def caeser_decrypt(encrypted_text_file, shift_parameter):
"""Dencrypt the string and return the text
Shift Paramter for right is taken as positive"""
result = ''
"""We will find the element in Key and replace by adding the index
For taking left as positive this sring will be reversed"""
key = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
with open('text_file', 'r') as myfile:
data=myfile.read()
for l in data.upper():
try:
i = (key.index(l) +26 - shift_parameter) % 26 """26 is added to make the substraction Non negative"""
result += key[i]
except ValueError:
result += l
return result.upper()
INFER_SHIFT()
def infer_shift(encrypted_text_file, language='abcdefghijklmnopqrstuvwxyz'):
"""for given language we have taken alphabets of the language
to find the alphabets which are not in the given language or not"""
with open('text_file', 'r') as myfile:
data=myfile.read()
""" If all the elements are in Given language Alphabet function will return True otherwise False """
for i in data:
if i is not in language:
return False
return True
INFER_SHIFT_LANGUAGE()
def infer_language(encrypted_text_file):
"""for given language we have taken alphabets of the language
to find the alphabets which are not in the given language or not"""
english='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
flag=0;
dutch='PUT_DUTCH_ALPHABET_HERE'
zulu='PUT_DUTCH_ALPHABET_HERE'
with open('text_file', 'r') as myfile:
data=myfile.read()
"""Cheking Alphabets of English"""
for i in data:
if i is not in english:
flag=1;
break
if(flag == 1):
return 'English'
"""Cheking Alphabets of Dutch"""
for i in data:
if i is not in dutch:
flag=1;
break
if(flag == 1):
return 'Dutch'
"""Cheking Alphabets of Zulu"""
for i in data:
if i is not in zulu:
flag=1;
break
if(flag == 1):
return 'Zulu'
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.