yep :)

of course, this would make the encoding mechanism very easy to work out - a shift left n bits is the same as multiplying by 2^n - so if you <<= 2, the result will just be 4 times bigger.

if someone with a decent understanding of maths saw this pattern, all they would have to do is work out how many LSBs were 0, shift right by that number (which can be done mentally very easily) and they would have all your original data.

On Mon, 29 Mar 2004 16:41:30 -0800, Anton Ganeshalingam <[EMAIL PROTECTED]> wrote:

yes this is good solution. But how would I convert integer values.

let say $num = '1234'

I may have to insert this into a integer field in a db. Hence, using your
approuch would cause me problems when I convert int data types. For example
trying to convert '10' will produce this '?ê?Ç'.


should I just use <<= and >>= for integer types

tks
Anton

-----Original Message-----
From: Sisyphus [mailto:[EMAIL PROTECTED]
Sent: Monday, March 29, 2004 2:43 PM
To: Anton Ganeshalingam
Cc: [EMAIL PROTECTED]
Subject: Re: shifting bits


Anton Ganeshalingam wrote:
Let's say my data is the following phrase 'Hello World'. This phrase is
represented in machine language in bits (assuming I'm right). So this was
the reason I thought I could insert the data into MS db after shifting a
bit.



Well, you'd have to left shift - and then right shift by the same amount to retrieve the original data. (If you right shift first you'll lose information.) So you'll probably be printing wide characters to the database. Is that going to pose a problem ? (I don't know the answer to that question.)

If you're trying to hide the data then there's probably a better
solution - eg use one of the encryption modules.

But here's one answer to (what I think is) your question. You just
replace 'H' with
chr(ord('H') << $shift), and do likewise for each of the other
characters in the string.

my $c = 'Hello World';
my $len = length($c);
my $shift = 3;

for(my $i = 0; $i < $len; $i++) {
    substr($c, $i, 1, chr(ord(substr($c, $i, 1)) << $shift));
    }

print $c, "\n";

# To recover the info:
for(my $i = 0; $i < $len; $i++) {
    substr($c, $i, 1, chr(ord(substr($c, $i, 1)) >> $shift));
    }

print $c, "\n";

__END__

Cheers,
Rob




_______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to