Interview Query

Words in Encrypted String

Start Timer

0:00:00

Upvote
0
Downvote
Save question
Mark as completed
View comments (6)
Next question

You are required to extract a specific word target_word from an encrypted document. Fortunately, you have the basic information needed to decrypt that document.

The equation used to encrypt the document is as follows:

En(x)=(I(s)+n)mod26E_n(x) = (I(\mathsf{s}) + n) \mod 26

Where:

  • s\mathsf{s} is a letter
  • I(x)I(x) is the number representing the position of the letter in the alphabet (1 for A, 2 for B, etc.)
  • nn is an arbitrary integer.
  • En(x)E_n(x) is the encrypted letter.

Return the number of occurrences of target_word in the document after decryption.

Note: The document only has upper case letters and spaces.

Example:

Input:

encrypted_document = 'WKH TXLFN EURZQ IRA MXPSV RYHU WKH ODCB GRJ'
n = 3
target_word = 'BROWN'

Output:

extract_word(encrypted_document,n,target_word) -> 1

Explanation:

After decrypting the document, you will have :

THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG

In which the target_word (BROWN) appears only once.

.
.
.
.
.


Comments

Loading comments