Actually, your method can be extended to almost any number of permitted characters.

1. Suppose the OPs format allows n different chars, dream up a private
encoding where each of those is given a number from 0 to n-1

2. Convert the 24 char input to this private encoding.

3. Treat this as a base n 24 digit number.

4. Use your encryption algorithm to create a key and message dependent number between 0 an n**24-1. It is *very* important that there is no
relationship between this value when used with different messages.

5. Add this number to the number from step 3, modulo n**24.

6. Reverse steps 3 and 2.

7. You now have an encrypted string of 24 chars, containing only allowed
chars.

8. As this is essentially a stream cipher, it does not prevent anyone
from changing the message without reading it.  For instance, an enemy
can change the 3rd letter from A to B by simply doing steps 2 and 3,
adding 1 * n * n, then doing step 6.


On 8/21/2012 2:10 PM, Charles Mills wrote:
6 bits will encode 64 different characters. So if you can restrict your
input to A-Z, a-z, 0-9, plus two other characters (space and period
perhaps) then 24 characters of input can be represented in 6*24 = 144
bits. 144/8 = 18 characters. It is a Programming 101 exercise to encode
64 different characters as 0 through 63 (six bits) and to pack those
six-bit integers into 18 bytes. Now you can encrypt those 18 bytes and
then base64 them to 24 characters. QED.

If your input consists of more than 64 different characters, then the
problem is impossible, unless there is some other pattern to the
characters than can be exploited to “save bits.”

/Charles/

*From:*owner-openssl-us...@openssl.org
[mailto:owner-openssl-us...@openssl.org] *On Behalf Of *Matt Caswell
(fr...@baggins.org)
*Sent:* Tuesday, August 21, 2012 5:49 AM
*To:* openssl-users@openssl.org
*Subject:* Re: OpenSSL DES generates '\n' in encrypted code

As Andrey has said the output from encryption is binary and so can be
any character (prinatable and non-printable). Therefore you are going to
have to do some kind of encoding of the output to force it to be
printable....this is going to increase the length no matter what.

What is the allowed set of characters for the input? The only solution I
can think of for you, if the output *has* to be 24 bytes, is to compress
the input prior to encryption. For example, if each character from the
input can be represented within 6 bits, then you could envisage a fairly
simple compression routine to compress the input from 24 bytes to 18. 18
bytes of input text would encrypt to 18 bytes of output (in binary
format). base64 encoding this output would result in 24 bytes of
printable characters.

Matt

On 21 August 2012 08:45, Tarun Thakur <tarun.tha...@nechclst.in
<mailto:tarun.tha...@nechclst.in>> wrote:


Hi,

Thanks for your reply..

But issue in base64 encoding is it will generate encoded test greater than
24 bytes. Application output should generate encrypted code exactly 24 bytes
as input.

Thanks,
Tarun




Andrey Koltsov-2 wrote:
 >
 > Hi Tarun.
 >
 > Output of every encryption function is always binary so it can contains
 > ANY character. You should encode this binary string to base64 or hex
 > format by yourself to pass it to your application. Do not forget to do
 > reverse encoding before decrypting.
 >
 >
 > Best regards,
 >
 > Andrey Koltsov
 > software developer
 > CyberplatSoft Ltd
 >
 > 21.08.2012 11 <tel:21.08.2012%2011>:16, Tarun Thakur пишет:
 >>
 >> Hi All,
 >>
 >> Issue is encrypted code contains '\n' which is an major issue for my
 >> software application.
 >>
 >> Given below is problem summarized.
 >>
 >> I have used OpenSSL library's  DES_ede3_ofb64_encrypt() function to
 >> perform
 >> encryption byte by byte on chunk of 24 bytes.
 >>
 >> For example:
 >> Input 24 bytes are:
 >> [root@tarun]# cat input.txt
 >> aaaaaaaabbbbbbbbcccccccc
 >>
 >> It encrypts 24 bytes successfully.
 >> Generates encrypted data, for example:
 >> [root@tarun]# cat code.txt
 >>       RÛÄSÒ
 >>            É#k7uÀÎCZ!°p
 >>
 >> Here comes problem for my software application, I want all 24 encrypted
 >> bytes in sequence WITHOUT '\n'.
 >> If possible in printable characters.
 >>
 >> Can you please help or guidance how to avoid '\n' in encrypted code?
 >> Is there any range of characters I can specify to DES algorithm
which can
 >> be
 >> used for encrypted code generation?
 >>
 >> Please help I am stuck.
 >>
 >> Thanks.
 >> Tarun
 >>



Enjoy

Jakob
--
Jakob Bohm, CIO, Partner, WiseMo A/S.  http://www.wisemo.com
Transformervej 29, 2730 Herlev, Denmark.  Direct +45 31 13 16 10
This public discussion message is non-binding and may contain errors.
WiseMo - Remote Service Management for PCs, Phones and Embedded
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to