Hi - I am trying to figure out exactly what the -hex in the DES::des command is supposed to achieve. From what I can see, it gives a nice hex-formatted string when you encrypt, however, there is no way that I can find to decrypt this hex string using the DES::des command.
In the following script, I would expect $plaintext to match $Answer, however it does not. It seems that plaintext is passed back as hex, which, upon decoding does not match $Answer.
#!/usr/bin/tclsh
package req des
set Answer abcdefg
set key 12345678
I really have no idea what was the intention, however, the following change would fix it to work as I expected, which is that when you pass in -hex during a decryption, it takes the string that you pass in and converts it to ascii before decrypting it:
217a218,221
> if {$opts(-hex)} {
> regsub -all -nocase {([0-9a-f][0-9a-f])} $data {[format %c 0x\1]} data
> set data [subst $data]
> }
239a244,247
> if {$opts(-hex)} {
> regsub -all -nocase {([0-9a-f][0-9a-f])} $data {[format %c 0x\1]} data
> set data [subst $data]
> }
259c267,269
< set r [Hex $r]
---
> if {[string equal $opts(-dir) "encrypt"]} {
> set r [Hex $r]
> }
Can anyone enlighten me with what the original intention was? Have I just overlooked something?
Cheers
Colin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
DES (Data Encryption Standard) is a symmetric-key algorithm used for encrypting and decrypting data. When combined with hexadecimal (hex) encoding, DES encryption can be represented in a more readable format. The process involves encrypting plain text using the DES algorithm and converting the resulting cipher text into a hexadecimal string. This format is often used in secure data transmissions, cryptography tools, and data storage systems to ensure that the encrypted output is compact and easy to handle while maintaining confidentiality.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi - I am trying to figure out exactly what the -hex in the DES::des command is supposed to achieve. From what I can see, it gives a nice hex-formatted string when you encrypt, however, there is no way that I can find to decrypt this hex string using the DES::des command.
In the following script, I would expect $plaintext to match $Answer, however it does not. It seems that plaintext is passed back as hex, which, upon decoding does not match $Answer.
#!/usr/bin/tclsh
package req des
set Answer abcdefg
set key 12345678
set encrypted [DES::des -hex -dir encrypt -key "$key" -- "$Answer"]
puts "$Answer"
set plaintext [DES::des -hex -dir decrypt -key "$key" -- "$encrypted"]
puts "$plaintext"
I really have no idea what was the intention, however, the following change would fix it to work as I expected, which is that when you pass in -hex during a decryption, it takes the string that you pass in and converts it to ascii before decrypting it:
217a218,221
> if {$opts(-hex)} {
> regsub -all -nocase {([0-9a-f][0-9a-f])} $data {[format %c 0x\1]} data
> set data [subst $data]
> }
239a244,247
> if {$opts(-hex)} {
> regsub -all -nocase {([0-9a-f][0-9a-f])} $data {[format %c 0x\1]} data
> set data [subst $data]
> }
259c267,269
< set r [Hex $r]
---
> if {[string equal $opts(-dir) "encrypt"]} {
> set r [Hex $r]
> }
Can anyone enlighten me with what the original intention was? Have I just overlooked something?
Cheers
Colin
DES (Data Encryption Standard) is a symmetric-key algorithm used for encrypting and decrypting data. When combined with hexadecimal (hex) encoding, DES encryption can be represented in a more readable format. The process involves encrypting plain text using the DES algorithm and converting the resulting cipher text into a hexadecimal string. This format is often used in secure data transmissions, cryptography tools, and data storage systems to ensure that the encrypted output is compact and easy to handle while maintaining confidentiality.