#!/usr/bin/env python3

'''
Title: ConvertNumPadCode.py
Description: Converts codes generated with number pad into clear text. Make sure to remove all punctuations from the
            secret code.
Author: pwnd-root
'''

''' Make sure to remove all punctuations from the secret code before running the script'''
secretCode = "444333 99966688 277733 7773323444664 84433 22244474433777 99966688 277733 666552999 99966688777 " \
             "777744277733 666333 84433 443344477778 4447777 44466 99966688777 4466688777733 84433 5533999 8666 84433"\
             " 55566622255 4447777 22335556669 4666 8666 727774447777 47777888 995559888 4555 47777888 44999988 " \
             "666555997 8555444888477744488866888648833369"

alphaDict = {
    '2' : 'A', '22' : 'B', '222' : 'C',
    '3' : 'D', '33' : 'E', '333' : 'F',
    '4' : 'G', '44' : 'H', '444' : 'I',
    '5' : 'J', '55' : 'K', '555' : 'L',
    '6' : 'M', '66' : 'N', '666' : 'O',
    '7' : 'P', '77' : 'Q', '777' : 'R', '7777' : 'S',
    '8' : 'T', '88' : 'U', '888' : 'V',
    '9' : 'W', '99' : 'X', '999' : 'Y', '9999' : 'Z'
}


def getPlainWord (block):

    cipherWord = block [0]
    plainWord = ''
    for i in range (1, len (block)):
        if block [i] == block [i-1]:  # Grouping all similar numbers
            cipherWord += block [i]
        else:
            plainWord += alphaDict [cipherWord]
            cipherWord = block [i]

    plainWord += alphaDict [cipherWord]

    return plainWord


plainText = ''
for block in secretCode.split ():
    plainText += getPlainWord (block)
    plainText += ' '

print (plainText)

