New Post:

Top Resume Builder in 2k21

Message Encryption-Skillrack

Message Encryption

                                      


                                   Image result for message encryption


To encrypt messages Jil will first decide on the number of columns C to use. Then Jil will pad the message with letters chosen randomly so that they form a rectangular matrix. Finally Jil will write down the message navigating the rows from left to right and then from right to left.

The program must accept the encrypted message M as input and then extract and print the original message (along with any additional padding letters) from the encrypted one based on the value of C.

Boundary Conditions:
Length of M is from 4 to 200.
2 <= C <= 20

Input Format:
First line will contain the string value of the encrypted message M.
Second line will contain the integer value of the column used for the encryption.

Output Format:
First line will contain the string value of the original message (along with any additional padding letters)

Sample Input/Output:

Example 1:
Input:
midinadiazne
3

Output:
madeinindiaz

Explanation:
m i d
a n i
d i a
e n z
Here z is the padding letter. The navigating across the rows mid (left to right) ina (right to left) and so on we come up with the encrypted message midinadiazne.


Example 2:
Input:
loaesfbnaiordilertenrdhdw
5

Output:
lionroaredandthebirdsflew

Explanation:
l o a e s
i a n b f
o r d i l
n e t r e
r d h d w

Here there are no padding letters. The navigating across the rows left to right and then from right to left we get loaesfbnaiordilertenrdhdw

Code:
#include<stdio.h>
#include <stdlib.h>
int main()
{
    int len;
    char str[400];
    scanf("%s",str);
    scanf("%d",&len);
    int n=strlen(str)/len;
    char str1[n][len];
    int i,j,k=0;
    for(i=0;i<n;i++)
    {
        if(i%2==0)
        {
            for(j=0;j<len;j++)
                str1[i][j]=str[k++];
        }
        else
        {
            for(j=len-1;j>=0;j--)
                str1[i][j]=str[k++];
        }
    }
    for(i=0;i<len;i++)
        for(j=0;j<n;j++)
            printf("%c",str1[j][i]);
}


cypatlyrmenomesloanueeleuap

9

3 comments

Write comments
Unknown
AUTHOR
Thursday, March 08, 2018 12:02:00 PM delete

hi there
I have used these tricks earlier, i want to suggest an app which is very helpful for the communication and it keeps our communication private.It encrypts all the messages,images and videos and prevent them from unauthorized viewing. This is The EnKryptonite App and it is revolutionary.
Download from:
App store & Google Play

Reply
avatar
Unknown
AUTHOR
Thursday, March 08, 2018 12:43:00 PM delete

Hi there,
I want to suggest an app for you guys which can be helpful for you to sharing your patient's records and to keep your records and communication or details safe and secure you must use the EnKryptonite app. Download form: https://goo.gl/BtxJi5 & https://goo.gl/8QcWQ2

Reply
avatar
keerthi
AUTHOR
Thursday, October 07, 2021 6:24:00 PM delete

#Python code below
m =input()
n=int(input())
l = []
p=[]
for i in range(0,len(m),n):
if(i%2==0):
s = m[i:i+n]
s = list(s)
l.append(s)
else:
s = m[i+(n-1):i-1:-1]
s = list(s)
l.append(s)
j=0
while(j<=n):
for i in range(len(l)):
for j in range(j,len(l[i])):
a = l[i][j]
p.append(a)
break
j = j+1
print(*p,sep="")

Reply
avatar

Just Give Your Feedback ConversionConversion EmoticonEmoticon