Menu

using des with -hex

Colin Ross
2009-04-22
2025-11-27
  • Colin Ross

    Colin Ross - 2009-04-22

    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

     
  • Yvette

    Yvette - 2024-03-07
    Post awaiting moderation.
  • wilian

    wilian - 2024-09-06

    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.

     
  • Liam Hudson Liam

    Post awaiting moderation.
  • Maria

    Maria - 2025-11-27

    Satisfy your cravings with a hearty meal that’s both delicious and filling. The tender, perfectly seasoned chicken pieces are paired with your favorite sides for a complete experience. The PC Tenders Fill Up offers a generous serving of crispy, juicy tenders that are sure to delight every bite. Whether you’re enjoying a quick lunch or a relaxed dinner, this meal is designed to keep you happy and satisfied. Treat yourself today to the ultimate comfort food with the PC Tenders Fill Up.

     

Log in to post a comment.