In this we are going to see a basic program on caesar cipher using iterators in Python Programming Language.
class Caesar:
def __init__(self, key, s):
self.key = key
self.s = s
self.l = len(self.s)
def __iter__(self):
self.c = 0
return self
def __next__(self):
if self.c < self.l:
res = chr((ord(self.s[self.c]) + self.key - 97) % 26 + 97)
self.c += 1
return res
else:
raise StopIteration
for i in Caesar(3, "hello"):
print(i, end="")
# Coded by Saahil
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP