0

For my beginners course Python I got the following assignment:

Write a program that decrypts messages in the following format:

<encryption_algorithm>:<key>:<message>

Example: caesar:42:01110010 10001111 10010110 10010110 10011001

The messages are encoded as binary strings with length 8 and have to be converted to ASCII. The messages can use Caesar and Vigenère encryption logarithms. It is not allowed to use the built-in functionality int(n,2). Tips: use string.split() when reading the input file. Start by parsing the input file.

I actually don't know where to start. Writing a function to convert binary in to decimals and vice versa? Write a Caesar decrypt and encrypt code?

Leslie
  • 31
  • 1
  • 5
  • 1
    You can do it in whatever order you want. Implement functions for each step, then put them all together for the final program. – Barmar Jan 28 '19 at 20:38
  • Convert your binary strings to ascii first (https://stackoverflow.com/questions/7396849/convert-binary-to-ascii-and-vice-versa), then run the decryption algorithm on the result. – Primusa Jan 28 '19 at 20:39
  • @Primusa Does that question have any answers that don't use `int(n, 2)` to parse a binary number? They're not allowed to use that here. – Barmar Jan 28 '19 at 20:40
  • 1
    See [How do I ask and answer homework questions?](https://meta.stackoverflow.com/a/334823/14122) -- particularly the guidance to ask about a *specific* problem with your *existing* implementation. If you don't have an existing implementation (because you're trying to figure out where to start), Stack Overflow isn't a good fit for your question. – Charles Duffy Jan 28 '19 at 20:42
  • See also [Are "how would I get started" questions too broad?](https://meta.stackoverflow.com/questions/308745/are-how-would-i-get-started-questions-too-broad), also on [meta]. – Charles Duffy Jan 28 '19 at 20:46
  • What is your expected output? Can you show us how it's done by hand/pseudocode? – Mr. Polywhirl Jan 28 '19 at 21:10
  • A Caesar cipher rotates the alphabet. A ⇒ B, B ⇒ C, ..,. Z ⇒ A. You can also increase the degree of shift, so shift 2 gives: A ⇒ C, B ⇒ D, ..., Y ⇒ A, Z ⇒ B. More details at https://en.wikipedia.org/wiki/Caesar_cipher. A Vigenère cipher is similar but the degrees of shift change according to a pattern instead of remaining constant throughout the message. More details at https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher. – BoarGules Jan 28 '19 at 21:35
  • You should try to write your own `int(n, 2)`, since it being disallowed means that it is likely very useful. – Jan Christoph Terasa Jan 28 '19 at 22:06

1 Answers1

1

I am not going to do the assignment for you but what I can do is give you a hint:

01110010 is 0 * 2**0 + 1 * 2**1 + 0 * 2**2...

Each bit needs to be multiplied by the appropriate power of 2, just like base 10:

1234567 is 7 * 10**0 + 6 * 10**1 + 5 * 10**2

You probably need a loop, but before that, you need to use the hint given in your assignment... You can use help(str.split) if you have a problem with that

Benoît P
  • 3,179
  • 13
  • 31