#ACSL2122S2. ACSL2122S2
ACSL2122S2
PROBLEM: Use this Fibonacci cypher to encode a given message into a list of numeric values or decode the numeric values into the original message.The Fibonacci sequence can start with any two non-negative integers and every term after that isthe sum of the two previous numbers. Therefore, if the first two numbers are 3 and 7, the sequence is 3, 7, 10, 17, 27, ... A Fibonacci cypher uses these numbers and an inputted "key’(alower-case letter in the alphabet) to encode a message into a list of numbers. Another person can decipher the message by knowing the 'key’ that was used and the starting 2 Fibonacci numbers. For each character in the message, integers are generated by using the following steps:
- Find the Fibonacci number with the same index as the character (e.g. using the sequenceabove, the lst character uses the number 3 and the 5th character uses the number 27).
- By using the inputted key, find a new letter that is offset by the Fibonacci number foundin Step 1. Wrap around to the beginning of the alphabet if necessary (e.g. if the key =p'and the Fibonacci number is 17, then the new letter is 'g' ).
- Find the number for each letter in the encoded message by adding the ASCIl code of the character in the string to 3 times the ASCIl code of the letter found in Step 2.We guarantee the message will not be longer than 200 characters or numbers.For this problem, there are two other things to consider:
- All characters with an odd-numbered index starting with the lst character in the stringwill shift characters to the right while all characters with an even-numbered index startingwith the 2nd character will shift characters to the left.
- At the beginning of every input, there will be an additional capital letter (E for encode or D for decode). Ifencoding, the message will be given to you. If decoding, the numberswill be given to you, each separated by a single space.
EXAMPLE: For the string“ACSL Sr-5 c2”, the initial Fibonacci numbers 3 and 7, and theletter 'h'as the 'key’, the encoded numbers are found as shown: The encoded message is“386 358 425 415 347 419 405 402 377 377 390 416
INPUT: There are 5 lines of data. Each line starts with either an E or a D followed by a single space. This will be followed by the two starting non-negative integers of the Fibonacci sequence separated by a single space, another single space, a single lower-case alphabetic character followed by a single space followed by the actual message to be encoded if you input an 'E' andthe numeric codes if you input a 'D'. Any typeable character on the keyboard except doublequotes may be included in the message
OUTPUT: For each line of data, print the integers separated by a single space that represent theencoded message OR print the string representing the decoded message.
SAMPLE INPUT:
E 3 7 h ACSL Sr-5 c2
E 0 1 s Python Programming is easier than programming in Java.
D 2 5 j 396 404 447 472 329 380 381 341 423 411 436 408 474 428 383 405 414 431 332 437 474 485 347 407 453 377 430 459 471 421 401 353 413 446 456 424 392 457 447 441 419 435 413 442 330
E 7 10 a Fibonacci Numbers are found in many places including the Mandelbrot Set.
D 6 1 z 379 479 341 447 448 329 381 397 402 402 395 462 404 383 425 434 446 383 469 468 405 464 408 449 433 329 390 425 429 395 446 420 449 368 417 397 363 363 395 429 443 383 464 395 446 344 408 458 445 431 335 367 402 394 475 419 391
SAMPLE OUTPUT
386 358 425 415 347 419 405 402 377 377 390 416
425 463 464 443 465 440 323 386 444 432 457 426 406 457 415 414 452 415 329 465 475 377 461 427 412 405 443 417 338 458 413 397 464 323 442 420 402 463 468 448 457 457 450 458 445 383 441 470 353 380 457 409 433 346
Help ME figure out how to solve this problem!
382 444 440 477 455 409 423 456 441 344 393 483 427 437 449 474 472 326 451 423 437 374 465 459 423 443 442 392 456 410 374 436 403 422 484 350 448 459 451 465 458 415 380 426 428 393 423 465 436 408 434 451 377 410 446 422 344 377 400 476 406 452 432 416 411 423 470 359 401 401 425 406
It is 9:30 in the morning EST but 6:30 on the West Coast.