Skip to content

Commit

Permalink
Merge pull request #52 from agiliq/develop
Browse files Browse the repository at this point in the history
Added more scripts
  • Loading branch information
kyogesh committed Aug 8, 2018
2 parents 029659a + 73d213f commit 9de36c1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
7 changes: 7 additions & 0 deletions networking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ Generate a mac Address
Generate a gravatar url from email
-----------------------------------

.. code-block:: python
import hashlib,urllib3
def gravatar_from_email(email):
hash = hashlib.md5(email.encode()).hexdigest()
Get IP address for a hostname
-----------------------------------
Expand Down
20 changes: 20 additions & 0 deletions password.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,29 @@ Validate that a password is least 8 chars, and contains at least 3 of lowercase,
Caesar Cipher
===============================

.. code-block:: python
from string import ascii_uppercase as upr, ascii_lowercase as lwr
def caesar_cipher(txt, offset=1):
_map = dict(list(zip(upr, upr[offset:] + upr[:offset])) + list((zip(lwr, lwr[offset:] + lwr[:offset]))))
return "".join([_map[el] if el in upr+lwr else el for el in txt])
Caesar cipher is one of the earliest known and simplest ciphers. It is a substitution cipher with a given offset.
Each letter is shifted by the offset, default value is 1.


Generate a UUID
========================

.. code-block:: python
import uuid
print(uuid.uuid4())
Generates a random uuid.


Generate a url safe UUID
=========================
Expand Down
9 changes: 9 additions & 0 deletions scripts/caesar_cipher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from string import ascii_uppercase as upr, ascii_lowercase as lwr

def caesar_cipher(txt, offset=1):
_map = dict(list(zip(upr, upr[offset:] + upr[:offset])) + list((zip(lwr, lwr[offset:] + lwr[:offset]))))
return "".join([_map[el] if el in upr+lwr else el for el in txt])

def test_caesar_cipher():
assert caesar_cipher('attack at dawn') == 'buubdl bu ebxo'
assert caesar_cipher('attack at dawn', offset=5) == 'fyyfhp fy ifbs'
2 changes: 2 additions & 0 deletions scripts/generate_uuid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import uuid
print(uuid.uuid4())
8 changes: 6 additions & 2 deletions scripts/rot_13_transformation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from string import ascii_uppercase as upr, ascii_lowercase as lwr

def rot13(txt):
map = dict(list(zip(upr, upr[13:] + upr[:13])) + list((zip(lwr, lwr[13:] + lwr[:13]))))
return "".join([map[el] for el in txt])
_map = dict(list(zip(upr, upr[13:] + upr[:13])) + list((zip(lwr, lwr[13:] + lwr[:13]))))
return "".join([_map[el] if el in upr+lwr else el for el in txt])


def test_rot13():
assert rot13('this text will transform') == 'guvf grkg jvyy genafsbez'
File renamed without changes.

0 comments on commit 9de36c1

Please sign in to comment.