+ 131

***DAILY CHALLENGE***: this one is about encryption & decryption. sounds complicated?!? Not this one ;)

TASK: write a function that get as input an ecnrypted text and a key (both strings) and outputs the decrypted text! input text: "#mpdgpuefzouquyyxzv#|#ypkerrzcovchvgjuwp#" let the program calculate and print the ouput. The '#' and '|' symbolize beginnig and end of string (don't use them in decryption)!!! EXTRA: use these functions to get the int value for a character (and vice versa): s = " abcdefghijklmnopqrstuvwxyz" function get_int(c): i = 0 while i < s.length(): if s[i] == c: return i print("ERROR") return -1 function get_char(i): while i < 0: i += s.length() i %= s.length() return s[i] ############################################ INFO: (you need to use One-Time-Pad & Cesar-Cipher) the key is encrypted the following way: msg = "hi" 1) OTP encryption (create a string size of msg. loop over key and msg and add their int values) random key = "zf" = 26 6, msg = "hi" = 8 9 --> encrypted text is: 26+8 6+9 = 34 15 = "go" ( = 7 15) 2) CESAR encryption (add to each int value (from char) the length of the key) only on key! key = "go" = 7 15 --> encrypted key is: 7+2 5+2 = 9 7 = "ig" now ouput is allways as follows: #key#|#txt# result: -----> "#ig#|#go#" (and 'nobody' knows what that means ^^) YOUR PART IS TO GO THE SAME WAY BACKWARDS MEANING: redo the cesar_cipher(- key.length) then redo the otp encryption by using get_char(key - encrypted) for all chars in key and encrypted Hope explanation is understandable ... if not check out my implementation: https://code.sololearn.com/cgq1RmKzNmlN/#py GOOD LUCK CODERS!!! If this one is too complicated try another one: -- will be uploaded soon --

28th Jul 2017, 4:20 PM
Julian Fechner
Julian Fechner - avatar
108 Antworten
22nd Aug 2017, 12:24 PM
Макс Б.
Макс Б. - avatar
+ 39
@aziz solves this issue with a perfect algorithm https://code.sololearn.com/cSIH9XiW6Hhz/?ref=app
2nd Aug 2017, 7:01 PM
Said BAHAOUARY
Said BAHAOUARY - avatar
+ 23
ok imagine the following situation: -my input is: msg = "hello" -now i create a random string with same length: key = "abdfs" -convert each character from msg and key into numbers msg = "hello" = [8,5,12,12,15] key = "abdfh" = [1,2,4,6,8] -now add each number sum = [9,7,16,18,32] -convert the numbers back to characters: encrypted = "igprf" decrypting is the same but now you subtract each number from key - each number from encrypted text (THIS IS YOUR PART)
28th Jul 2017, 7:39 PM
Julian Fechner
Julian Fechner - avatar
+ 16
@Vari it's a cesar encryp, k=2
2nd Aug 2017, 7:10 PM
Said BAHAOUARY
Said BAHAOUARY - avatar
+ 15
@@ julian there is a bug in your post...(not in code; in post) u took a=1 up to z=26 so g is 7 of course now in your example it came up 34-15 u changed it 7-15 why???????? SHOULD NOT IT BE 8-15 (34-26)=8 so it wont be" go" it will be "ho"
21st Aug 2017, 3:30 PM
sayan chandra
sayan chandra - avatar
22nd Aug 2017, 2:39 PM
furryferret3
furryferret3 - avatar
+ 11
Sounds like a good challenge though I think I'll pass. My phone can only do so much 😂
28th Jul 2017, 9:52 PM
Garikai
Garikai - avatar
22nd Aug 2017, 11:16 AM
JULIUS FREDRICK
JULIUS FREDRICK - avatar
22nd Aug 2017, 2:03 PM
Game'OBot
Game'OBot - avatar
+ 7
This was written before the challenge so it's mostly FYI: https://code.sololearn.com/W85GKwfubQ6Z/?ref=app The demo analyzes the ciphertext, guesses the key and decrypts the first part of Alice in Wonderland. ...or you can paste this at line 17 (it should look familiar): var sampleText="TQYBO SXQBBUDWU: jxyi edu yi qrekj udshofjyed & tushofjyed. iekdti secfbysqjut?!? Dej jxyi edu ... OEKH FQHJ YI JE WE JXU IQCU MQO RQSAMQHTI CUQDYDW: hute jxu suiqh_syfxuh(- auo.budwjx) jxud hute jxu ejf udshofjyed ro kiydw wuj_sxqh(auo - udshofjut) veh qbb sxqhi yd auo qdt udshofjut Xefu unfbqdqjyed yi kdtuhijqdtqrbu ... yv dej sxusa ekj co ycfbucudjqjyed WEET BKSA SETUHI!!! Yv jxyi edu yi jee secfbysqjut jho qdejxuh edu mybb ru kfbeqtut ieed";
21st Aug 2017, 8:30 PM
Kirk Schafer
Kirk Schafer - avatar
+ 6
#include <stdio.h> #include <ctype.h> #define MAXSIZE 1024 void encrypt(char*); void decrypt(char*); int menu(); int main(void) { char c, choice[2], s[MAXSIZE]; while(1) { menu(); gets(choice); if((choice[0]=='e')||(choice[0]=='E')) { puts("Input text to encrypt->"); gets(s); encrypt(s); } else if((choice[0]=='d')||(choice[0]=='D')) { puts("Input text to decrypt->"); gets(s); decrypt(s); } else break; } return 0; } void encrypt(char*str) { int n=0; char *p=str, q[MAXSIZE]; while(*p) { if(islower(*p)) { if((*p>='a')&&(*p<'x')) q[n]=toupper(*p + (char)3); else if(*p=='x') q[n]='A'; else if(*p=='y') q[n]='B'; else q[n]='C'; } else { q[n]=*p; } n++; p++; } q[n++]='\0'; puts(q); } void decrypt(char*str) { int n=0; char *p=str, q[MAXSIZE]; while(*p) { if(isupper(*p)) { if((*p>='D')&&(*p<='Z')) q[n]=tolower(*p - (char)3); else if(*p=='A') q[n]='x'; else if(*p=='B') q[n]='y'; else q[n]='z'; } else { q[n]=*p; } n++; p++; } q[n++]='\0'; puts(q); } int menu() { puts("To encrypt, input e or E\n"); puts("To decrypt, input d or D\n"); puts("To exit, input any other letter\n"); puts("Your choice:->\n"); return 0; }
22nd Aug 2017, 8:03 AM
Mohammad Selim
Mohammad Selim - avatar
+ 6
Public static void main (String[]args){ system.out.println("Java has ruined my life"); }
22nd Aug 2017, 1:22 PM
Kerri Cunningham
Kerri Cunningham - avatar
+ 5
HEY PEOPLE OUT THERE. I'M BACK FROM VACATION. AND ANOTHER DAY MEANS ANOTHER CHALLENGE. CHECK IT OUT!!! https://www.sololearn.com/discuss/622449/?ref=app SOLUTION WILL BE UPLOADED TOMORROW NIGHT!
13th Aug 2017, 8:03 PM
Julian Fechner
Julian Fechner - avatar
22nd Aug 2017, 2:03 AM
Michael Mofo J Turner
Michael Mofo J Turner - avatar
22nd Aug 2017, 10:42 AM
Stoyan Todorov
Stoyan Todorov - avatar
+ 4
This is my code ,, I try to make it simple https://code.sololearn.com/c2Ov4DE0jpE0/?ref=app
22nd Aug 2017, 10:27 AM
Sara Mohammed
Sara Mohammed - avatar
+ 4
WOW ... THANK'S TO YOU ALL FOR COTD!!! :)
22nd Aug 2017, 10:58 AM
Julian Fechner
Julian Fechner - avatar
+ 4
22nd Aug 2017, 2:29 PM
Stoyan Todorov
Stoyan Todorov - avatar
22nd Aug 2017, 5:16 PM
m abrate
m abrate - avatar
+ 4
last week it was around midnight. I decided to write a program that could encrypt any text and I wrote half of it but when I woke up the next morning I didn't understand anything of the code that I wrote the day before that was how I didn't created an encryption program 😅😅😅
29th Aug 2017, 8:32 AM
keivan Ipchi
keivan Ipchi - avatar