Question

Simple-ish encryption of a String without unicode (using ASCII)

Asked by: rfwoolf

Hi Experts

I'm going to be converting a string of characters into a barcode format. These characters will be your standard ASCII characters, notably A-Z, 0-9 and perhaps a few symbols if possible.
The problem is, I want to encrypt this string, so that even if someone has a barcode scanner, what they scan will be gibberish. But when encrypting the string, I don't want the length of the string to increase too much because the barcode can only support a maximum number of characters. Add to this problem, I think my barcode format (PDF417) can only support ASCII and not unicode (I think a unicode character takes up a lot of space).
I'm NOT saying that the encrypted version should be the exact same length as the decrypted version.

I'm using Delphi, and need a simple encryption and decryption process please.


This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-07-01 at 11:20:02ID24537280
Topics

Delphi Programming

,

Encryption for Network Security

Participating Experts
6
Points
500
Comments
17

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Using a barcode scanner
    Interested in writting a POS program and need to incorporate a barcode scanner - any ideas would be appreciated
  2. Encryption\Decryption
    Do you have any good logic for encryption and decryption I have one but the problem with that is for some characters it returns special charater like '#0 now this one character so i cannot event replace this single quote with two single quotes. Can anyone of you give some b...
  3. barcode programming in delphi
    hi i am new to delphi. I want to develop a database application that can utilize barcode scanner but i don't know where to start. Could you guys tell me if there are some books or tutorial/information regarding barcode programming in delphi ? how do I start ?
  4. encryption / decryption
    Hello all. Didn't know where to post this as it involves both Java and Delphi, so if it is in the wrong area, sorry, and can someone move it to the correct one. Anyhow: I am looking for a way to encrypt a String in Java, and decrypt it in delphi (and visa versa). I can en...
  5. delphi encrypt / decrypt files
    Any simple and free COMPONENT to be used with D6 to encrypt and decrypt files ? How strong is the encryption ? Is it easy to be broken ? Can it encrypt large text files (more than 500 Kbytes text files) ?
  6. Encrypt , decrypt in delphi and C#
    aAyone can show me two functions encrypt(input,key) and decrypt(input,key) that working both in c# and delphi. because I want to encypt in delphi then can decrypt in c# encypt in c# then can decrypt in delphi. Thank experts.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: SteveBayPosted on 2009-07-01 at 11:24:55ID: 24756861

Free and as simple of complex as you like.
http://sourceforge.net/projects/tplockbox/

 

by: 8080_DiverPosted on 2009-07-01 at 11:39:43ID: 24756954

Piece of cake.  Here's the basics of the process.

  1. Create a string constant that includes A-Z and 0-9 but in a scrambled order (DecryptStr); 
  2. Create a second string that includes all of the characters you will need to encrypt (EncryptStr) ina different scrambled order;
     
  3. Create a function (EncryptIt)  that accept a string as an input value and return a string as a result value; 
  4. In the EncryptIt function, you first create a numeric equivalent of the string to be encrypted by multiplying 1 by the Pos() of the first character in the EncryptStr string then continuing the multiplication  by the Pos() of each of the succeeding characters; 
  5. Now that you have a numereric equivalent of the string, all you need to do is reverse the process, using the DecryptStr string and working with the modulus (i.e. the remainder after dividing by) based upon the number of characters in the DecryptStr string (and I would build the resulting string from left to right ;-);
     
  6. In order to decrypt the string, you build a a similar (DecryptIt) function that also accepts a string parameter and returns a string result; 
  7. The DEcryptIt process uses the same processing except it first uses the Decrypt string and then uses the EncryptStr (And the Modulo arithmetic needs to be based on the number of characters in the Encrypt string), again building the string from left to right. 

I can supply a basic set of these two functions if you need them (I have used them for various similar task ;-).

 

by: aikimarkPosted on 2009-07-01 at 12:52:10ID: 24757578

ROT13 -- expanded to accomodate your alphabet size.

 

by: JohnjcesPosted on 2009-07-01 at 13:58:42ID: 24758169

How about something really simple using xor?

unit Crypt32;
interface
 
//const
//  StartKey	= 981;  	{Start default key}
//  MultKey	  = 12674;	{Mult default key}
//  AddKey	  = 35891;	{Add default key}
 
var
  StartKey, MultKey, AddKey : Integer;
 
function Encrypt(const InString:string; StartKey,MultKey,AddKey:Integer): string;
function Decrypt(const InString:string; StartKey,MultKey,AddKey:Integer): string;
 
implementation
 
{$R-}
{$Q-}
{*******************************************************
 * Standard Encryption algorithm - Copied from Borland *
 *******************************************************}
function Encrypt(const InString:string; StartKey,MultKey,AddKey:Integer): string;
var
  I : Byte;
begin
  Result := '';
  for I := 1 to Length(InString) do
  begin
    Result := Result + CHAR(Byte(InString[I]) xor (StartKey shr 8));
    StartKey := (Byte(Result[I]) + StartKey) * MultKey + AddKey;
  end;
end;
{*******************************************************
 * Standard Decryption algorithm - Copied from Borland *
 *******************************************************}
function Decrypt(const InString:string; StartKey,MultKey,AddKey:Integer): string;
var
  I : Byte;
begin
  Result := '';
  for I := 1 to Length(InString) do
  begin
    Result := Result + CHAR(Byte(InString[I]) xor (StartKey shr 8));
    StartKey := (Byte(InString[I]) + StartKey) * MultKey + AddKey;
  end;
end;
{$R+}
{$Q+}
 
end.

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:

Select allOpen in new window

 

by: 8080_DiverPosted on 2009-07-01 at 14:17:27ID: 24758320

XOR can result in some ASCII characters that are not printable and, therefore, probably not going to be within the charactersetof the Bar Codes.

For instance, XOR '0' with '7' results in a BELL character [Hex(07)]  . . . and so does 'P' XOR 'W'.

That's why I proposed an Encrypt and Decrypt string of characters that areprintable and also very probably included in the Bar Code characterset.

 

by: aikimarkPosted on 2009-07-01 at 14:26:24ID: 24758391

@Stevebay & Johnces

Since the encrypted string must be supported by the barcode, I don't think these suggested methods would work in this (narrow) case.

From the barcode description, a Base64 encoding wouldn't work.  We would have to take the encrypted output and create a Base36 (approx) code.

===========
@rfwoolf

Both an alphabetic substitution and a simple rotation will give you an easy, fast and reliable encryption (no change in length) that will still be represented in your barcode.  What you haven't told us is "How secure do you need this?"

If this is to thwart the mildly curious, then you have two good algorithms.  If you need stronger encryption, you will need to describe the importance/value of this string you are encrypting and to what lengths your 'spys' are willing to go to decrypt this.

 

by: Geert_GruwezPosted on 2009-07-01 at 22:25:46ID: 24760658

the main issue will be the length of your string when encrypting
if you need something that nobody understands ... just use numbers in the barcode
save your texts in a table, a column text, a column id (auto number), and a column barcode number
have a routine to generate such a number
you can even make it simple for people to understand like year/month/day/indexnr

they'll think they have figured it out and say it's the date and a index
and 98% will stop hacking

that's just the start off course, as this is the index of a record in a table
no correlation to any text or string whatsoever
and you won't have any problem with string lengths

you could let the database encrypt the text for you in the text column

 

by: aikimarkPosted on 2009-07-02 at 05:47:07ID: 24762664

this ROT13 code lifted from a nonexistant web page.  Notice that the alphabets have been shifted by 13 positions.

// Perform ROT13 function on a string
function sRot13 (S: string): string;
 
function sRot13 (S: string): string;
const
  upperAZ: array ['A'..'Z'] of Char = 'NOPQRSTUVWXYZABCDEFGHIJKLM';
  loweraz: array ['a'..'z'] of Char = 'nopqrstuvwxyzabcdefghijklm';
var
  i: Integer;
  s1: string;
begin
  s1 := '';
  for i := 1 to Length(S) do
  begin
    if s[i] in ['A'..'Z'] then
      s1 := s1 + upperAZ[s[i]]
    else if s[i] in ['a'..'z'] then
      s1 := s1 + loweraz[s[i]]
    else
      s1 := s1 + s[i];
  end;
  Result := s1;
end;
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:

Select allOpen in new window

 

by: ozoPosted on 2009-07-02 at 13:04:28ID: 24767252

A mod 36 or mod 26 version of RC4 could preserve the length and character set without being quite as obvious as rot13
http://en.wikipedia.org/wiki/RC4#The_pseudo-random_generation_algorithm_.28PRGA.29

 

by: aikimarkPosted on 2009-07-02 at 14:06:34ID: 24767714

@ozo

"obvious" is the key word here.  Thus my questions about the value of data being protected and the sophistication level of attackers.  Obvious to us might be sufficiently obscured to the mildly curious.

 

by: ozoPosted on 2009-07-02 at 14:29:02ID: 24767889

I make no claim whether ROt13 is inadequate or RC4 is adequate for this purpose.
The key questions about the value of the data and the types of attacks it might endure are yet to be answered.

 

by: rfwoolfPosted on 2009-07-16 at 02:34:22ID: 24867729

I ended up using TPLockBox as recommended by SteveBay.
It isn't ideal however because it does increase my string by about 33% using Blowfish (other encryptions increased the string by even more), but I'm sure if I tinker with it some more I can get this down.

 

by: aikimarkPosted on 2009-07-16 at 06:42:31ID: 24868906

@rfwolf

The size increase is probably due to the encoding (Base64?) rather than the encription algorithm.

 

by: rfwoolfPosted on 2009-09-14 at 02:01:00ID: 25323730

Okay I need some advice - not sure exactly what to say if I open a new question...
Basically my problem persists - if I take a string and encrypt it using TLockBox II get an inflation of about 27%.
Now somebody said this is because of Base64 -- which I don't really understand, but looking at TLockbox it looks like they all use Base64.
Basically I don't mind an inflation, but maybe of 10%, not 27%.
My INPUT data is a 171-character string. After encryption it is a 236 string.
That's inflation of 65 characters or 27.5%.

Any advice please.

 

by: rfwoolfPosted on 2009-09-14 at 02:55:50ID: 25323949

Upon reviewing this question I can see for example ozo's comments may be helpful, but without code I simply can't try it - even pseudo-code from wikipedia.

 

by: aikimarkPosted on 2009-09-16 at 21:51:22ID: 25352979

@rfwoolf

It is possible/probable that an encrypted string will contain characters with ASCII values that can not be displayed, such as CR or LF.  Sometimes an ASCII 0 character might appear in the encrypted string, causing problems if stored or passed as PChar.

Base64 encoding results in a string of alphanumeric characters, which eliminates some of the problems I identified in the preceding paragraph.

For more information, see
http://en.wikipedia.org/wiki/Base64

 

by: 8080_DiverPosted on 2009-09-17 at 08:25:21ID: 25357247

@rfwoolf ,

Now that you have accepted a solution, this thread should no longer be used.  You would need to open a new question, oribably rephrasing it so that it doesn't duplicate this one.

Over this weekend, I may be able to locate the substitution cypher unit that I used a while back.  There was little, if any, increase in the size of the text but I would need to know the full set of characters that can be represented by your bar-code software and also the full set of characters that you would need to be able to encrypt.  If you need to be able to encrypt more characters than the number available in the barcoding, then things could get somewhat complicated but that can be handled, too.  (Math, as well as SQL, is your friend. ;-)  However, like I said, this is not a 2 minute task. ;-)

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...