0

Untranslate Tools for Cryptography, This made for string chars that was translated with string.translate from python modules.

For my stack, i think why me not build a program un-translate for it? wink

1. Stack Problem

>>> import string
>>> make_trans = string.maketrans('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
                                  'CDEFGHIJKLMNOPQRSTUVWXYZABcdefghijklmnopqrstuvwxyzab')
>>> trans = string.translate("Summon Agus", make_trans)
>>> trans
'Uwooqp Ciwu'
>>> 

Yup, 'Uwooqp Ciwu' its my problem. 

2. Test It

agaust@agaust:~/Python-Code/Translate$ python un_translate.py right 3 "Uwooqp Ciwu"
Vxpprq Djxv
Wyqqsr Ekyw
Xzrrts Flzx
agaust@agaust:~/Python-Code/Translate$ python un_translate.py left 4 "Uwooqp Ciwu"
Tvnnpo Bhvt
Summon Agus
Rtllnm zftr
Qskkml yesq

3. Find Solved

'Uwooqp Ciwu' is 'Summon Agus', beautiful right? cheeky

And thereis script to un-translate of it, save this with name un_translate.py or else, you can chmod it with 777 to make it executable.
or directly with python commands in your terminal like this: $ python un_translate.py

#!/usr/bin/python
# -*- coding: utf-8 -*-
import string, sys

def _help():
    print "<----------------------------------------------------------------------------------------------->"
    print "[>] Untranslate Tools for Cryptography                                                          |"
    print "[>] Build by Summon Agus, blog: https://python.web.id                                           |"
    print "[>] Made for string was translate with `string.translate` from python modules.                  |"
    print "[+] --------------------------------------------------------------------------------------------|"
    print "[?] Untranslate left :   ./un_translate.py left [<number> or -f <for full>] <string_translate>  |"
    print "[?] Untranslate right:   ./un_translate.py right [<number> or -f <for full>] <string_translate> |"
    print "<----------------------------------------------------------------------------------------------->"

"""Thanks to: `Iron Fist` for this `shift` function.
Answered: http://stackoverflow.com/a/34555735/3445802"""
def shift(s, step, side='right'):
    step %= len(s) #Will generate correct steps even step > len(s)
    if side == 'right':
        return s[-step:]+s[:-step]
    elif side == 'left':
        return s[step:]+s[:step]
    else:
        print '[-] Please, Specify either Right or Left shift!'
        return sys.exit()

""" `_untranslate()` is function of translator"""
def _untranslate(command, length, en_translate):
    command         = sys.argv[1]
    length          = sys.argv[2]
    en_translate    = sys.argv[3]

    chrs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
    #for complete chars, use this:
    #chrs = string.printable.replace(' tnrx0bx0c', '')

    """This `_full_length()` function use if param of `length` is `-f`.
    So, there will returning `untranslate` with full length of param:`chrs`."""
    def _full_length():
        no = 0
        for numb in range(len(chrs)):
            no += 1
            make_trans = string.maketrans( shift(chrs, no, command), chrs)
            print string.translate(en_translate, make_trans )

    """This `_specific_length()` function use if param of `length` use specific number"""
    def _specific_length():
        no = 0
        for numb in range(int(length)):
            no += 1
            make_trans = string.maketrans( shift(chrs, no, command), chrs)
            print string.translate(en_translate, make_trans )

    """Define if `command` is `left or `right`, if not they, it will return to _help() function."""
    if command == 'left' or command == 'right':
        try:
            if length == '-f':
                _full_length()
            else:
                _specific_length()
        except ValueError:
            pass
    else:
        return _help()

if __name__ == "__main__":
    try:
        command         = sys.argv[1]
        length          = sys.argv[2]
        en_translate    = sys.argv[3]
        _untranslate(command, length, en_translate)
    except IndexError:
        _help()

This script was available on my github: https://github.com/agusmakmun/Some-Examples-of-Simple-Python-Script/blob/master/Encryption/un_translate.py

Hope it usefull..

project python

Your Answer

blog comments powered by Disqus