System Security HM 9
System Security HM 9
System Security HM 9
Q1)
if len(user_input) != len(real_passwd): # if length of both strings are not same, then they
cannot be anagram
return False
if user_input[i] != real_passwd[i]:
return False
return True
An anagram happens when a string is compared to another string and it contain the same
characters. The order of characters can be different. An example is “abcdef” and “defabc”
are anagram of each other.
a) The problem with such a system is that it is based on comparison of strings of the same
length and same type of characters in the strings but not necessarily the correct position
of the characters. This type of comparisons are not suitable for password checking cos
for password comparison, it need not only check the correct length but also need check
that the characters are in the precise order.
b) We can learn the length and anagram of real_password when interacting with the
function. The password can be recovered if we add sort and compare conditions into the
function.
Import collect
if len(real_passwd)!=len(user_input):
return
counts=collect.defaultalpha(int)
for char in real_passwd:
counts[char]+=1
if counts[char]<0:
return True
c)
else:
difference = 0
for i in range(len(real_passwd)):
if real_passwd [i] != user_input [i]:
difference += 1
return difference
print(edit_distance("smitten", "sitting")) #3
print(edit_distance("median", "medium")) #2
From computer science perspective, edit distance is one way of quantifying how two non-
similar strings or words are related to one another by counting the minimum number of
operations required to transform one string onto the other. Edit distances can be found in
applications such as language processing and bioinformatics, where automatic spelling
correction can help user to correct a misspelled word by selecting words from a dictionary
that have a low distance to the word that is spelled. In the case of bioinformatics, it can be
used to quantify similar DNA sequences, when viewed as strings of the.
The edit distance between two strings is the minimum number of character insertions,
deletions or substitutions needed to change from one string to the other. An example is the
edit distance between the words "smitten" and "sitting" is three: append a "m", substitute
the "e" for "i" and append a "g".