Binary operator x ^ y calculates a bitwise exclusive OR of x and y (also known a
ID: 673894 • Letter: B
Question
Binary operator x ^ y calculates a bitwise exclusive OR of x and y (also known as XOR; you can solve the problem without knowing the particular detail of the operation). It is common in cryptography and telecommunications to calculate the so-called checksum of a transmitted string. While there are many ways to calculate a checksum, one of the easiest is to calculate the XOR of the ASCII charcodes of all characters in the string. Write a program that shall ask the user to enter a 6-character string. The program then shall calculate the checksum of the string (that is, the XOR of all charcodes), find out the ASCII character whose charcode equals the checksum, append that character to the end of the original string, and display the new string. For example, if the user enters 'hello!', your program shall display 'hello!C'.Explanation / Answer
def checkSum():
print("Enter 6 character string")
s= "hello!"
c = s[0]
for i in range(1,6):
c ^= s[i]
print "%s%s"%(s,c);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.