This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Decryption DES with ECD - without Padding

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello every one! (and i cant find good forum with my topic, sorry)
I have problem with one simple(?) example I have file with a hexa cryptogram and i should decrypt this with DES and ECB and i can't use a "Padding". Could you help me?
Key: "1234567890123456"
Output should be a string of letters of the Latin alphabet.
I attached file with cryptogram, (okey i cant attach) but it should be:
59 c8 4b 6b 56 fc 3e 2e 57 43 cd 32 92 72 77 00 69 a9 c8 2d 07 a1 2a 29 a6 bd 98 7c 0b 15 a3 f9 e9 ed 49 a7 d8 e9 dc cf 24 91 3c 68 d0 b2 ef 6a 41 6a 6d b9 79 df ea 41 5f 82 60 55 cf a3 e7 e3 58 1f 3b fc 1f 21 6e 77 28 42 ab fc fb ba 37 f5 57 ff b3 57 6a d5 52 bd b2 12 ec 14 f8 3e 1c aa e0 c4 82 98 e8 b5 8d 2d f2 15 f0 a0 a0 3d 37 45 7f d6 d0 20 b9 cb fc 69 c0 a3 52 eb 3d c4 5b 81 86 c4 22 42 c8 7b b1 d5 4a e7 90 61 dc a7 e6 04 b5 dd 10 74


 
Ranch Foreman
Posts: 103
7
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that looks pretry straight forward. You have the cipher, its mode and the key. Now you just have to use javax.crypto.Cipher to do the magic.
Show us what you got so far and where you struggle. I'm sure we can help you to get this working.
 
Marshal
Posts: 69035
275
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and welcome to the Ranch

I shall try adding this th‍read to our security forum.
 
Bob Winter
Ranch Foreman
Posts: 103
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a small hint: The JavaDoc for the class lists common cipher suites and their modes as a String that you can pass to the Cipher.getInstance() method. The one you're looking for is in the middle.
About the key: For someone not used to Javas crypto framework it may look easy as "Just use XXX as input.", but be aware: Unfortunately it's a bit more tricky than that. It depends on how the key is encoded to get some useful SecretKey instance.
As you're supposed to use an operation mode without padding it may can get a bit complicated to figure out the correct way to do it as there is no way to check if the key was valid cryptographically - as each output of ECB without padding is at least somewhat valid. This way it depends on knowledge about what the output should look like. But as you given at least some information about the key and the output it should be rather obvious when you got it right - as when you mess something up at least part of the output will not be right.
In addition to all that: The mode you're supposed to used is what's known as a block cipher. Using a block cipher means that you have to operate on the data with a fixed blocksize. DES for example uses a blocksize of 64 bits, or 8 bytes. As your given ciphertext is way longer than just 8 bytes you can't just give it as a whole as input and get one big output out of it but you have to come up with a way to process the data in chunks.
When you first got your head around it all this makes sense and becomes way more clear. Just don't give up if your first tries fail - crypto is hard.
 
Barto John
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eh... Stil... I can't decrypt. Could you help me? someone ? What should be the result? And maybe I'll find my mistake.
 
Saloon Keeper
Posts: 11924
253
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's easier if you show us what you've tried and we'll comment on your code.
 
Bob Winter
Ranch Foreman
Posts: 103
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Barto John wrote:Eh... Stil... I can't decrypt. Could you help me? someone ? What should be the result? And maybe I'll find my mistake.


As I already wrote: Just show us what you got so far and someone (maybe me?) here surely will be able to help you along ...

In fact: You're given all you need, it's really not that hard. You may struggle a bit at first, but once you got it working you'll see it comes down to just a few lines.
 
Barto John
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay... I Used a CTS -> https://en.wikipedia.org/wiki/Ciphertext_stealing.
Thank you all for your willingness and prose  :-D (joke)
 
Stephan van Hulst
Saloon Keeper
Posts: 11924
253
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using CTS? The assignment explicitly mentions ECB.
 
Barto John
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In brief: Cipher.length()%64! = 0. You know, bit, blocks.

Ciphertext stealing (CTS) is a general method of using a block cipher mode of operation that allows for processing of messages that are not evenly divisible into blocks without resulting in any expansion of the ciphertext, at the cost of slightly increased complexity.
 
Stephan van Hulst
Saloon Keeper
Posts: 11924
253
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I missed that the ciphertext was not a multiple of 8 bytes.

Java's built-in CTS mode uses CBC as the block cipher mode, which is not what you want. I noticed that BouncyCastle has a CTSBlockCipher class. Try constructing one with with a DESEngine.
 
Bob Winter
Ranch Foreman
Posts: 103
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aside from CTS - did you solved your problem? If so: It would be nice for others might want to learn from it to post your final code as an example.
 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic