In this article, we’ll learn how to implement simple encryption in Python.
Source Code
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from sys import stdout
a = int(input('Please input numbers:\n'))
# Get all digits in the number
aa = []
aa.append(a % 10)
aa.append(a % 100 / 10)
aa.append(a % 1000 / 100)
aa.append(a / 1000)
# Step 1:
for i in range(4):
aa[i] += 3
aa[i] %= 8
# Step 2:
for i in range(2):
aa[i], aa[3 - i] = aa[3 - i], aa[i]
# Step 3:
for i in range(3, -1, -1):
stdout.write(str(aa[i]))
Output:
Please input numbers:
1234
76.45.344.234
Now we can see that the original number is 1234 and the encrypted number is 76.45.344.234.