The most basic encryption method is to map a char to another char by a certain math rule.
Because every char has an ASCII value, we can manipulate this value with a simple math expression. 
For example 'a' + 1 would give us 'b', because 'a' value is 97 and 'b' value is 98.

You will need to write a method which does exactly that - 

get a string as text and an int as the rule of manipulation, and should return encrypted text.
for example:

encrypt("a",1) = "b"

 *Full ascii table is used on our question (256 chars) - so 0-255 are the valid values.*
 
Good luck.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Mathematics

Starter code: def encrypt(text, rule):
	

Solutions:
def encrypt(text, rule):
	return ''.join((chr((ord(i) + rule) % 256) for i in text))


def encrypt(text, rule):
	return ''.join((chr((ord(c) + rule) % 256) for c in text))


def encrypt(text, key):
	return ''.join((chr(ord(ch) + key & 255) for ch in text))


def encrypt(text, rule):
	return ''.join((chr(ord(c) + rule & 255) for c in text))


def encrypt(text, rule):
	return ''.join([chr((ord(a) + rule) % 256) for a in text])


def encrypt(text, rule):
	return ''.join((chr((ord(x) + rule) % 256) for x in text))


def encrypt(text, rule):
	return ''.join([chr((ord(s) + rule) % 256) for s in text])


def encrypt(text, rule):
	return ''.join(map(lambda x: chr((ord(x) + rule) % 256), text))


def encrypt(text, rule):
	encrypted_text = list(text)
	for i in range(len(encrypted_text)):
		encrypted_text[i] = chr((ord(encrypted_text[i]) + rule) % 256)
	return ''.join(encrypted_text)


def encrypt(text, rule):
	retval = ''
	for sss in text:
		retval += chr((ord(sss) + rule) % 256)
	return retval