mavili has asked for the wisdom of the Perl Monks concerning the following question:

Please help me out here! I have a simple encryption like follows:
$cipher = Crypt::Twofish->new($key); $ct = $cipher->encrypt('encrypted text 1');
print $cipher->decrypt($ct); gives back the decrypted text (plain text I started with). However, instead of decrypt($ct) when I try to copy and paste the content of the variable $ct, it gives me totally different piece of text! How can I get my plain text back by using the 'content' of the variable $ct and not the variable. This is due to the fact that I will be saving the encrypted text into a file, and I wanna get the plain text whenever I decrypt the cipher text.

Replies are listed 'Best First'.
Re: encryption using Twofish
by GrandFather (Saint) on Aug 12, 2012 at 23:57 UTC

    How about you show us a short sample script that demonstrates your problem so that we can reproduce exactly the issue you have? There are a few fuzzy areas in the description you have given so far that make it hard to know just where your real issue may lie.

    True laziness is hard work
Re: encryption using Twofish
by aitap (Curate) on Aug 13, 2012 at 07:50 UTC

    As long as encrypt() returns binary data, you'll have to encode it in some text reperesentation in order to be able to copy-paste it. Try MIME::Base64.

    Alternatively, write the contents of this variable to a file (possibly opened in binary mode, see binmode).

    Sorry if my advice was wrong.
Re: encryption using Twofish
by zentara (Cardinal) on Aug 13, 2012 at 10:44 UTC