[Python] Basic Encoder/Decoder with Caesar CIpher


def CaesarCiper(str_,DeEn, key): a_=[] for i in str_: if(DeEn == "D"): a_.append(ord(i) - key) else: a_.append(ord(i) + key) def_="" for j in a_: def_ = def_ + chr(j) return def_


>>> a = CaesarCiper("This is a test with long sentence for Decode/Encode the message","E",2) >>> a 'Vjku"ku"c"vguv"ykvj"nqpi"ugpvgpeg"hqt"Fgeqfg1Gpeqfg"vjg"oguucig' >>> b = CaesarCiper(a,"D",2) >>> b 'This is a test with long sentence for Decode/Encode the message'

[Python 1] Basic Python

Assuming that the traits of a person can be determined by a number which is a summarization of the values in their name. For example, if a = 1, b = 2, c = 3, etc. then, the name Mathhoang would be 87.

A small snippet python can be:


1
2
3
4
5
6
def calTraits():
 input_ = input("enter name: ").lower()
 sum_ = 0
 for i in input_:
  sum_ = sum_ + (ord(i) - 96)
 return sum_
another way for it:
1
 sum([(ord(i) - 96) for i in input("enter name:").lower()])

The examples show that we can use python in many differnt ways to implement your ideas!
Related Posts Plugin for WordPress, Blogger...