Back
Close

Encryption/Decryption Software

Statement

 Goal

You are given:
1. mode, either "encrypt" or "decrypt"
2. key, containing 26 words, each signifying the letter at its index
3. message, A sentence.

If mode is "encrypt":
message will only contain UPPERCASE characters and space
For each character in message you must find its replacement in key by taking the index of the letter, "A" -> 0, "B" -> 1, etc..
You have to print each letter separated by 1 space and each word separated by 3 spaces

Else:
In message each letter is separated by 1 space and each word separated by 3 spaces
For each character in message you must find its alphabetical replacement in key by index. If the character is at index 0 it is "A", etc...
You have to print each letter separated by no spaces and each word separated by 1 space
Input
Line 1: mode
Line 2: key
Line 3: message
Output
Either ENCRYPTED or DECRYPTED message
Constraints
Mode = "encrypt" or "decrypt"
0 < Length of key < 500
0 < Length of message < 101
Example
Input
encrypt
! @ # $ % ^ & * ( ) [ ] { } | / < > ` ~ - _ = + ? .
HELLO WORLDZ WHAT IS UP
Output
* % ] ] |   = | > ] $ .   = * ! ~   ( `   - /

Tags
EncryptionDecryption

Difficulty
Easy

Test cases
Encrypt special Test
Input
encrypt ! @ # $ % ^ & * ( ) [ ] { } | / < > ` ~ - _ = + ? . HELLO WORLDZ WHAT IS UP
Output
* % ] ] | = | > ] $ . = * ! ~ ( ` - /

Validator 1 Validator
Input
encrypt ! @ # $ % ^ & * ( ) [ ] { } | / < > ` ~ - _ = + ? . HELLO WORLD SUP
Output
* % ] ] | = | > ] $ ` - /

Decrypt special Test
Input
decrypt ! @ # $ % ^ & * ( ) [ ] { } | / < > ` ~ - _ = + ? . * % ] ] | = | > ] $ . = * ! ~ ( ` - /
Output
HELLO WORLDZ WHAT IS UP

Validator 2 Validator
Input
decrypt ! @ # $ % ^ & * ( ) [ ] { } | / < > ` ~ - _ = + ? * % ] ] | = | > ] $ ` - /
Output
HELLO WORLD SUP

Encrypt number Test
Input
encrypt 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 DO RE MI FA SO LA TI DO
Output
3 14 17 4 12 8 5 0 18 14 11 0 19 8 3 14

Validator 3 Validator
Input
encrypt 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 SA RE GA MA PA DA NI SA
Output
18 0 17 4 6 0 12 0 15 0 3 0 13 8 18 0

Decrypt number Test
Input
decrypt 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 3 14 17 4 12 8 5 0 18 14 11 0 19 8 3 14
Output
DO RE MI FA SO LA TI DO

Validator 4 Validator
Input
decrypt 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 18 0 17 4 6 0 12 0 15 0 3 0 13 8 18 0
Output
SA RE GA MA PA DA NI SA

Encrypt morse Test
Input
encrypt ._ _... _._. _.. . .._. __. .... .. .___ _._ ._.. __ _. ___ .__. __._ ._. ... _ .._ ..._ .__ _.._ _.__ __.. IT IS JUST TOO HARD TO WRITE MORSE SPENT THIRTY MINUTES FOR IT
Output
.. _ .. ... .___ .._ ... _ _ ___ ___ .... ._ ._. _.. _ ___ .__ ._. .. _ . __ ___ ._. ... . ... .__. . _. _ _ .... .. ._. _ _.__ __ .. _. .._ _ . ... .._. ___ ._. .. _

Validator 5 Validator
Input
encrypt ._ _... _._. _.. . .._. __. .... .. .___ _._ ._.. __ _. ___ .__. __._ ._. ... _ .._ ..._ .__ _.._ _.__ __.. MORSE CODE IS HARD BUT IT IS FOR THE BEST
Output
__ ___ ._. ... . _._. ___ _.. . .. ... .... ._ ._. _.. _... .._ _ .. _ .. ... .._. ___ ._. _ .... . _... . ... _

Decrypt morse Test
Input
decrypt ._ _... _._. _.. . .._. __. .... .. .___ _._ ._.. __ _. ___ .__. __._ ._. ... _ .._ ..._ .__ _.._ _.__ __.. .. _ .. ... .___ .._ ... _ _ ___ ___ .... ._ ._. _.. _ ___ .__ ._. .. _ . __ ___ ._. ... . ... .__. . _. _ _ .... .. ._. _ _.__ __ .. _. .._ _ . ... .._. ___ ._. .. _
Output
IT IS JUST TOO HARD TO WRITE MORSE SPENT THIRTY MINUTES FOR IT

Validator 6 Validator
Input
decrypt ._ _... _._. _.. . .._. __. .... .. .___ _._ ._.. __ _. ___ .__. __._ ._. ... _ .._ ..._ .__ _.._ _.__ __.. __ ___ ._. ... . _._. ___ _.. . .. ... .... ._ ._. _.. _... .._ _ .. _ .. ... .._. ___ ._. _ .... . _... . ... _
Output
MORSE CODE IS HARD BUT IT IS FOR THE BEST

Solution language

Solution

Stub generator input