Skip to content

Conversation

@Mephitzzz
Copy link

No description provided.

Copy link
Member

@Pancham1603 Pancham1603 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this code in a file to get it approved

def cipher(enc, code):

    alphabet1 = ['0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
    alphabet = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

    grid = []

    for x in alphabet:
        list = []
        char = alphabet.index(x)
        list.append(x)
        char = alphabet.index(x)
        for y in range(char,27):
            try:
                list.append(alphabet[y])
            except IndexError:
                pass
        for z in range(0,char):
            try:
                list.append(alphabet[z])
            except IndexError:
                pass
        grid.append(list)

    
    codelist = []
    enclist = []
    for x in code:
        codelist.append(x)
    for x in enc:
        enclist.append(x)

    map = {}
    length = len(enclist)
    count = 0
    decrypted = ''
    for x in range(length):
        codechar = codelist[count]
        encryptchar = enclist[x]
        count += 1
        if count == len(codelist):
            count = 0

        
        for h in grid:
            if h[0] == codechar:
                index = h.index(encryptchar)
                char = alphabet1[index]
                if char == '0':
                    char='A'
                decrypted+=char
    return decrypted
test = int(input())

for x in range(test):
    enc = input()
    code = input()
    print(cipher(enc,code))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants