Re: shifting bits
Anton Ganeshalingam 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 Yes, you can do that if you want (or must). It's unnecessary from a perl perspective. Is it necessary from the database perspective ? As far as perl is concerned, it doesn't matter whether you shift the int value, or shift the ASCII values of the characters. In either case you still get the original number back when you reverse the procedure. Cheers, Rob ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: shifting bits
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
RE: shifting bits
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
Re: shifting bits
crypt:: modules ARE the simple solution :) give it a key and some data, and you have industry-level data protection, as safe as the very code of your program - or even better than that if you use a password as the source for the key... and all it takes is about 2-3 instructions. On Mon, 29 Mar 2004 14:45:00 -0800, Anton Ganeshalingam <[EMAIL PROTECTED]> wrote: Mike, yes I wanted to use crypt:: modules but my boss looking for a simple solution. tks Anton -Original Message- From: Arms, Mike [mailto:[EMAIL PROTECTED] Sent: Monday, March 29, 2004 2:29 PM To: 'Anton Ganeshalingam'; 'Mike Jackson' Cc: [EMAIL PROTECTED] Subject: RE: shifting bits This combined with this quote from Anton: I'm trying to avoid people looking at the data without proper access sounds like he is wanting to do some really simplistic encryption of his data that will be stored in a database accessible by others. Anton, this will be incredibly easy to decipher. Maybe you should look into the real Crypt::* modules to significantly increase your security. Of course, this depends on you not storing your keys in the clear either (and a list of other concerns). -- Mike Arms -Original Message- From: Anton Ganeshalingam [mailto:[EMAIL PROTECTED] Sent: Monday, March 29, 2004 2:19 PM To: 'Mike Jackson'; Anton Ganeshalingam Cc: [EMAIL PROTECTED] Subject: RE: shifting bits 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. tks Anton -Original Message- From: Mike Jackson [mailto:[EMAIL PROTECTED] Sent: Monday, March 29, 2004 12:49 PM To: Anton Ganeshalingam Cc: [EMAIL PROTECTED] Subject: Re: shifting bits it sounds like you weren't talking about bit-shifting integers... What do you mean by shifting a byte of data by any number? On Mon, 29 Mar 2004 12:23:21 -0800, Anton Ganeshalingam <[EMAIL PROTECTED]> wrote: > Mike, >Thanks for your reply. But I'm confused not by your answer but my > lack of knowledge on this matter. How would I convert the data like > "Hello > World". Should I convert to acssii first ? > > tks > Anton > > -Original Message- > From: Mike Jackson [mailto:[EMAIL PROTECTED] > Sent: Monday, March 29, 2004 12:16 PM > To: Anton Ganeshalingam; '[EMAIL PROTECTED]' > Subject: Re: shifting bits > > > from perlop: > > Shift Operators > > Binary ``<<'' returns the value of its left argument shifted left by the > number of bits specified by the right argument. Arguments should be > integers. (See also Integer Arithmetic.) > > Binary ``>>'' returns the value of its left argument shifted right by the > number of bits specified by the right argument. Arguments should be > integers. (See also Integer Arithmetic.) > > so, > > use Win32::ODBC; > $db = new Win32::ODBC('DBQ=myDB.mdb;Driver={Microsoft Access Driver > (*.mdb)};') or die "can't open database"; > $db->Sql "SELECT * FROM myTable WHERE someVal=$myConditionalVal"; > if ($db->FetchRow) { >my %datahash = $db->DataHash; >$datahash{myVal} <<= $datahash{shiftAmt}; >$db->Sql "UPDATE myTable SET myVal=$datahash{myVal} WHERE > someVal=$datahash{someVal}"; > } > $db->Close(); > > would retrieve a row from myTable where someVal equals $myConditionalVal, > shift myVal left by shiftAmt bits, and re-write... if you wanna do the > whole table, just push all the result hashes onto an array, and when > done, > go through the array, pop each one, do the shift and re-write... > > which would be even easier with a tied hash - but I havent yet played > with > tied hashes... > > > > On Mon, 29 Mar 2004 11:54:43 -0800, Anton Ganeshalingam > <[EMAIL PROTECTED]> wrote: > >> >> >>> Hello to all, >>>I'm writing a perl program that will take a byte of data and shift >>> (right or left) it by any number and write it to a MS access DB. Since >>> Perl is free type language how would you accomplish this on perl. >>> >>> Please help. >>> >>> tks >>> Anton ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
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
RE: shifting bits
Mike, yes I wanted to use crypt:: modules but my boss looking for a simple solution. tks Anton -Original Message- From: Arms, Mike [mailto:[EMAIL PROTECTED] Sent: Monday, March 29, 2004 2:29 PM To: 'Anton Ganeshalingam'; 'Mike Jackson' Cc: [EMAIL PROTECTED] Subject: RE: shifting bits This combined with this quote from Anton: I'm trying to avoid people looking at the data without proper access sounds like he is wanting to do some really simplistic encryption of his data that will be stored in a database accessible by others. Anton, this will be incredibly easy to decipher. Maybe you should look into the real Crypt::* modules to significantly increase your security. Of course, this depends on you not storing your keys in the clear either (and a list of other concerns). -- Mike Arms > -Original Message- > From: Anton Ganeshalingam > [mailto:[EMAIL PROTECTED] > Sent: Monday, March 29, 2004 2:19 PM > To: 'Mike Jackson'; Anton Ganeshalingam > Cc: [EMAIL PROTECTED] > Subject: RE: shifting bits > > 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. > > tks > Anton > > -Original Message- > From: Mike Jackson [mailto:[EMAIL PROTECTED] > Sent: Monday, March 29, 2004 12:49 PM > To: Anton Ganeshalingam > Cc: [EMAIL PROTECTED] > Subject: Re: shifting bits > > > it sounds like you weren't talking about bit-shifting > integers... What do you mean by shifting a byte of > data by any number? > > On Mon, 29 Mar 2004 12:23:21 -0800, Anton Ganeshalingam > <[EMAIL PROTECTED]> wrote: > > > Mike, > > Thanks for your reply. But I'm confused not by your > answer but my > > lack of knowledge on this matter. How would I convert the data like > > "Hello > > World". Should I convert to acssii first ? > > > > tks > > Anton > > > > -Original Message- > > From: Mike Jackson [mailto:[EMAIL PROTECTED] > > Sent: Monday, March 29, 2004 12:16 PM > > To: Anton Ganeshalingam; '[EMAIL PROTECTED]' > > Subject: Re: shifting bits > > > > > > from perlop: > > > > Shift Operators > > > > Binary ``<<'' returns the value of its left argument > shifted left by the > > number of bits specified by the right argument. Arguments should be > > integers. (See also Integer Arithmetic.) > > > > Binary ``>>'' returns the value of its left argument > shifted right by the > > number of bits specified by the right argument. Arguments should be > > integers. (See also Integer Arithmetic.) > > > > so, > > > > use Win32::ODBC; > > $db = new Win32::ODBC('DBQ=myDB.mdb;Driver={Microsoft Access Driver > > (*.mdb)};') or die "can't open database"; > > $db->Sql "SELECT * FROM myTable WHERE someVal=$myConditionalVal"; > > if ($db->FetchRow) { > >my %datahash = $db->DataHash; > >$datahash{myVal} <<= $datahash{shiftAmt}; > >$db->Sql "UPDATE myTable SET myVal=$datahash{myVal} WHERE > > someVal=$datahash{someVal}"; > > } > > $db->Close(); > > > > would retrieve a row from myTable where someVal equals > $myConditionalVal, > > shift myVal left by shiftAmt bits, and re-write... if you > wanna do the > > whole table, just push all the result hashes onto an array, > and when > > done, > > go through the array, pop each one, do the shift and re-write... > > > > which would be even easier with a tied hash - but I havent > yet played > > with > > tied hashes... > > > > > > > > On Mon, 29 Mar 2004 11:54:43 -0800, Anton Ganeshalingam > > <[EMAIL PROTECTED]> wrote: > > > >> > >> > >>> Hello to all, > >>> I'm writing a perl program that will take a byte of > data and shift > >>> (right or left) it by any number and write it to a MS > access DB. Since > >>> Perl is free type language how would you accomplish this on perl. > >>> > >>> Please help. > >>> > >>> tks > >>> Anton ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: shifting bits
Anton Ganeshalingam wrote: > > but why would you want to shift a bit of textual data? It would no > > longer be text.. > > I'm trying to avoid people looking at the data without proper access Why not just use an encryption module? ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: shifting bits
This combined with this quote from Anton: I'm trying to avoid people looking at the data without proper access sounds like he is wanting to do some really simplistic encryption of his data that will be stored in a database accessible by others. Anton, this will be incredibly easy to decipher. Maybe you should look into the real Crypt::* modules to significantly increase your security. Of course, this depends on you not storing your keys in the clear either (and a list of other concerns). -- Mike Arms > -Original Message- > From: Anton Ganeshalingam > [mailto:[EMAIL PROTECTED] > Sent: Monday, March 29, 2004 2:19 PM > To: 'Mike Jackson'; Anton Ganeshalingam > Cc: [EMAIL PROTECTED] > Subject: RE: shifting bits > > 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. > > tks > Anton > > -Original Message- > From: Mike Jackson [mailto:[EMAIL PROTECTED] > Sent: Monday, March 29, 2004 12:49 PM > To: Anton Ganeshalingam > Cc: [EMAIL PROTECTED] > Subject: Re: shifting bits > > > it sounds like you weren't talking about bit-shifting > integers... What do you mean by shifting a byte of > data by any number? > > On Mon, 29 Mar 2004 12:23:21 -0800, Anton Ganeshalingam > <[EMAIL PROTECTED]> wrote: > > > Mike, > > Thanks for your reply. But I'm confused not by your > answer but my > > lack of knowledge on this matter. How would I convert the data like > > "Hello > > World". Should I convert to acssii first ? > > > > tks > > Anton > > > > -Original Message- > > From: Mike Jackson [mailto:[EMAIL PROTECTED] > > Sent: Monday, March 29, 2004 12:16 PM > > To: Anton Ganeshalingam; '[EMAIL PROTECTED]' > > Subject: Re: shifting bits > > > > > > from perlop: > > > > Shift Operators > > > > Binary ``<<'' returns the value of its left argument > shifted left by the > > number of bits specified by the right argument. Arguments should be > > integers. (See also Integer Arithmetic.) > > > > Binary ``>>'' returns the value of its left argument > shifted right by the > > number of bits specified by the right argument. Arguments should be > > integers. (See also Integer Arithmetic.) > > > > so, > > > > use Win32::ODBC; > > $db = new Win32::ODBC('DBQ=myDB.mdb;Driver={Microsoft Access Driver > > (*.mdb)};') or die "can't open database"; > > $db->Sql "SELECT * FROM myTable WHERE someVal=$myConditionalVal"; > > if ($db->FetchRow) { > >my %datahash = $db->DataHash; > >$datahash{myVal} <<= $datahash{shiftAmt}; > >$db->Sql "UPDATE myTable SET myVal=$datahash{myVal} WHERE > > someVal=$datahash{someVal}"; > > } > > $db->Close(); > > > > would retrieve a row from myTable where someVal equals > $myConditionalVal, > > shift myVal left by shiftAmt bits, and re-write... if you > wanna do the > > whole table, just push all the result hashes onto an array, > and when > > done, > > go through the array, pop each one, do the shift and re-write... > > > > which would be even easier with a tied hash - but I havent > yet played > > with > > tied hashes... > > > > > > > > On Mon, 29 Mar 2004 11:54:43 -0800, Anton Ganeshalingam > > <[EMAIL PROTECTED]> wrote: > > > >> > >> > >>> Hello to all, > >>> I'm writing a perl program that will take a byte of > data and shift > >>> (right or left) it by any number and write it to a MS > access DB. Since > >>> Perl is free type language how would you accomplish this on perl. > >>> > >>> Please help. > >>> > >>> tks > >>> Anton ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: shifting bits
I'm trying to avoid people looking at the data without proper access tks Anton -Original Message- From: Mike Jackson [mailto:[EMAIL PROTECTED] Sent: Monday, March 29, 2004 1:54 PM To: Anton Ganeshalingam Cc: [EMAIL PROTECTED] Subject: Re: shifting bits yes, the string is represented by an array of 8 bit values (or 16 if using unicode), and the chr() and asc() (from memory) functions convert between text and value representations. but why would you want to shift a bit of textual data? It would no longer be text.. On Mon, 29 Mar 2004 13:18:56 -0800, Anton Ganeshalingam <[EMAIL PROTECTED]> 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. > > tks > Anton > > -Original Message- > From: Mike Jackson [mailto:[EMAIL PROTECTED] > Sent: Monday, March 29, 2004 12:49 PM > To: Anton Ganeshalingam > Cc: [EMAIL PROTECTED] > Subject: Re: shifting bits > > > it sounds like you weren't talking about bit-shifting integers... What do > you mean by shifting a byte of data by any number? > > On Mon, 29 Mar 2004 12:23:21 -0800, Anton Ganeshalingam > <[EMAIL PROTECTED]> wrote: > >> Mike, >> Thanks for your reply. But I'm confused not by your answer but my >> lack of knowledge on this matter. How would I convert the data like >> "Hello >> World". Should I convert to acssii first ? >> >> tks >> Anton >> >> -Original Message- >> From: Mike Jackson [mailto:[EMAIL PROTECTED] >> Sent: Monday, March 29, 2004 12:16 PM >> To: Anton Ganeshalingam; '[EMAIL PROTECTED]' >> Subject: Re: shifting bits >> >> >> from perlop: >> >> Shift Operators >> >> Binary ``<<'' returns the value of its left argument shifted left by the >> number of bits specified by the right argument. Arguments should be >> integers. (See also Integer Arithmetic.) >> >> Binary ``>>'' returns the value of its left argument shifted right by >> the >> number of bits specified by the right argument. Arguments should be >> integers. (See also Integer Arithmetic.) >> >> so, >> >> use Win32::ODBC; >> $db = new Win32::ODBC('DBQ=myDB.mdb;Driver={Microsoft Access Driver >> (*.mdb)};') or die "can't open database"; >> $db->Sql "SELECT * FROM myTable WHERE someVal=$myConditionalVal"; >> if ($db->FetchRow) { >>my %datahash = $db->DataHash; >>$datahash{myVal} <<= $datahash{shiftAmt}; >>$db->Sql "UPDATE myTable SET myVal=$datahash{myVal} WHERE >> someVal=$datahash{someVal}"; >> } >> $db->Close(); >> >> would retrieve a row from myTable where someVal equals >> $myConditionalVal, >> shift myVal left by shiftAmt bits, and re-write... if you wanna do the >> whole table, just push all the result hashes onto an array, and when >> done, >> go through the array, pop each one, do the shift and re-write... >> >> which would be even easier with a tied hash - but I havent yet played >> with >> tied hashes... >> >> >> >> On Mon, 29 Mar 2004 11:54:43 -0800, Anton Ganeshalingam >> <[EMAIL PROTECTED]> wrote: >> >>> >>> >>>> Hello to all, >>>>I'm writing a perl program that will take a byte of data and shift >>>> (right or left) it by any number and write it to a MS access DB. Since >>>> Perl is free type language how would you accomplish this on perl. >>>> >>>> Please help. >>>> >>>> tks >>>> Anton >>> >>> ___ >>> 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 > ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs