1. cypher tools preview, unsigned 32bits
- Posted by isaac <isaaca at MINDSPRING.COM> Apr 18, 1999
- 353 views
I've been working on a small toolkit for creating cyphers. So far included: a Feistel utility (you provide the F-function routine ID), an S-box function, a sequence shuffler, and a latin square builder/shuffler. In the works: hash function(s), entropy hooks. I intend to release an early, highly unoptimised but well documented version of the library within a week. I'm open to suggestions if there's anything else you'd like to see included, but I will not include actual encryption algorithms. My question: is there a way to perform bitwise operations on 32bit UNSIGNED integers(actually a sequence of integers)? I need to alternate between 32bit bitwise and standard arithmetic operations. The best idea I've thought of is to allocate enough memory to accommodate the sequence, then use a poke4() followed by a peek4u() to coax the interpreter into interpreting the values as I'd like it to, but this is inefficient. I would suggest one or both of the following additions to the language: A set of unsigned bitwise logical operators, such as xor_ubits, not_ubits, etc. A pair of functions, signed_32() and unsigned_32(), which would force 32bit values to be interpreted as signed or unsigned. any suggestions would be appreciated, isaac
2. Re: cypher tools preview, unsigned 32bits
- Posted by "C. K. Lester" <cklester at TICNET.COM> Apr 18, 1999
- 357 views
For what would this be used? >I've been working on a small toolkit for creating cyphers.
3. Re: cypher tools preview, unsigned 32bits
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> Apr 18, 1999
- 357 views
- Last edited Apr 19, 1999
> My question: is there a way to perform bitwise operations on 32bit UNSIGNED > integers(actually a sequence of integers)? I need to alternate between > 32bit bitwise and standard arithmetic operations. The best idea I've > thought of is to allocate enough memory to accommodate the sequence, then > use a poke4() followed by a peek4u() to coax the interpreter into > interpreting the values as I'd like it to, but this is inefficient. You could use normal 32-bit atoms. The only thing where it would go wrong is during outputting the value and when comparing to a signed value. For output, just add half the scope. The floating point value will be signinicant enough. For comparisment of unsigned values with singed values, you could just use one generic routine, that makes a signed out of the unsigned, rather than visa-versa. And yes, its that easy. global function compare_signed (object is, atom us, integer bits) us = us - power (2, bits) return compare (is, us) end function global function convert (object is, integer bits) -- loose precision! is = is + power (2, bits) end function You can use the normal int_to_bytes () to store unsigned values to disk. Ralf
4. Re: cypher tools preview, unsigned 32bits
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> Apr 18, 1999
- 354 views
- Last edited Apr 19, 1999
> My question: is there a way to perform bitwise operations on 32bit UNSIGNED > integers(actually a sequence of integers)? I need to alternate between > 32bit bitwise and standard arithmetic operations. The best idea I've > thought of is to allocate enough memory to accommodate the sequence, then > use a poke4() followed by a peek4u() to coax the interpreter into > interpreting the values as I'd like it to, but this is inefficient. You could use normal 32-bit atoms. The only thing where it would go wrong is during outputting the value and when comparing to a signed value. For output, just add half the scope. The floating point value will be signinicant enough.To compare unsigned values with singed values, you could just use one generic routine, that makes a signed out of the unsigned, rather than visa-versa. And yes, its that easy. global function scompare (object is, atom us, integer bits) us = us - power (2, bits) return compare (is, us) end function global function to_signed (object is, integer bits) -- loose precision! is = is + power (2, bits) end function global function to_unsigned (object us, integer bits) -- loose precision! is = is - power (2, bits) end function Usage: atom unsigned, signed unsigned = to_unsigned (5, 32) -- unsigned 32 bits value unsigned = unsigned * 2 + 2323 -- normal arithemetic works signed = 2343 -- if signed > unsigned then becomes if scompare (signed, unsigned, 32) = 1 then That's it... oh and when you want to switch the signed & unsigned value, use: if scompare (unsigned, signed, -32) = 1 then You can use the normal int_to_bytes () to store unsigned values to disk using all precision. Ralf N.
5. Re: cypher tools preview, unsigned 32bits
- Posted by Davi Figueiredo <davitf at USA.NET> Apr 19, 1999
- 367 views
- Last edited Apr 20, 1999
>My question: is there a way to perform bitwise operations >on 32bit UNSIGNED integers(actually a sequence of integers)? I wrote some functions to do that some time ago, when I was creating some encryption routines myself, but they handled only atoms (not sequences). But it is not difficult to create one that would work also with sequences. Here is a routine that would XOR the elements of a sequence with the elements of other one, and return unsigned values (untested code): function unsigned_xor(object a1,object a2) object result result=3Dxor_bits(a1,a2) result=3Dresult+((result<0)*#100000000) return result end function It is easy to change it to perform other operations (and, or, not). If you want to perform these operations only to atoms, and not to sequences, this one should be faster (also untested): function uxor(atom a1,atom a2) atom result result=3Dxor_bits(a1,a2) if result<0 then result=3Dresult+#100000000 end if return result end function I hope it helps. I am looking forward to seeing your toolkit, as I am interested in cryptography too. Regards, Davi T. Figueiredo davitf at usa.net ____________________________________________________________________ Get free e-mail and a permanent address at http://www.amexmail.com/?A=3D1=