Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need an encryption method that will encrypt (not encode) a file name so that the resulting encrypted string can be stored in a SQLite table.
The encryption method must not insert #0 characters into the resulting TString (non ANSI).
Example:
Before: hello_world.txt
After: y381a82jzseoi1
The length of the two strings needs to be the same, or at least not more than 10-15% longer in length.
Any suggestions?
I would do it like this:
Convert from text to binary using TEncoding.GetBytes. You'll need to decide on an encoding. To support Unicode UTF-8 or UTF-16 would be the most likely choices. Often UTF-8 is the most efficient in terms of space.
Encrypt using your chosen encryption algorithm. This converts the binary data returned by TEncoding.GetBytes into encrypted binary data.
Save the encrypted binary data to the database as a blob.
Note that I have avoided converting the encrypted binary data back to text. This deals with your desire to avoid null-terminators by simply side-stepping the issue. The key point for you to recognise is that encryption operates on binary data rather than text. It is an exceptionally common misconception that encryption algorithms operate on text.
If, for some reason that I do not anticipate, you simply must store the data as text, then you should encode it from binary to text. You could implement base255 encoding to avoid having null terminators, and keep the size down.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I see a lot of codes like this:
if WA > SPACES
move WA to WA2
end-if
What are the advantages that this is checked? Is it more efficient to check if it is empty than to just move it anyways?
Additional information:
WA and WA2 can be simple structures (without fillers) but also just simple attributes. They are not redifined and typed as chars or structures of chars. They can be either low-values (semantically NULL) or have alphanumeric content.
Nobody can tell you what the actual reason is except for the people who coded it, but here is a very probable reason:
Usually this is accompanied with an ELSE that would cover what happens if the value is less than spaces, but in this case I would assume that what every happens to this data later is relying on that field NOT being LOW-VALUES or some funky non-displayable control character.
If I had to guess, I would assume that WA2 is initialized to spaces. So doing this check before the move ensures that nothing lower than spaces would be moved to that variable. Remember, less than spaces does not mean empty, it just means that hex values of that string are less than X'40' (so for example is the string was full of low values, it would be all X'00'. So I would guess that its more about ensuring that the data is valid than efficiency.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
there is a thing called dummy trap in one hot encoder that is when we encode the categorical column with 3 categories lest say a,b,and c then with one hot encoder we get 3 categories like or columns a, b ,and c but when we use get_dummies we get 2 columns instead a, and b then it is save from dummy trap. is one hot encoding exposed to dummy trap or it takes care of it . am i right? which one is save of dummy trap? or is it ok to use both with our removing columns, iam using the dataset for many algorithms.
looking for help . thanks in advance.
OneHotEncoder cannot process string values directly. If your nominal features are strings, then you need to first map them into integers.
pandas.get_dummies is kind of the opposite. By default, it only converts string columns into one-hot representation, unless columns are specified.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
In an application I need to convert values between metric, British imperial and US imperial, e.g. kilos to stones + pounds (UK) to pounds (US). How best to store the user-inputted data?
Is it better to convert all inputted values to e.g. metric and save as a float, or keep the user inputted data as say a literal string and interpret on each application launch?
The maths/equations etc is all good, it's more knowing what the most efficient structure is for storing values that can be represented in different ways, in a database?
It really comes down to what precision you need. Storing the value as String might be safe but is extremely inefficient. For simple 1 to 1 value conversions it might be efficient enough. For converting thousands of values it probably won't.
I would go with scalar types representing the most complex value the user is able to enter manually. Derive calculations from those original values to avoid losing complexity.
One note: since you're dealing with real world values (I presume), ditch the sign and use the unsigned variants if you're going with scalar value types.
This is the approach I use, Make an NSObject called WeightObject that have 2 propertiesL
1- the value the user entered (for example 3)
2- a unit the user used example:(KiloGrams/pounds etc..).
lastly save the object. this way yo keep the record exactly as user entred, and you make the method inside the object to return the value in KG or in punds etc...
so later you say float x = myWeightObject.KilosValue
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Ok. I am completely stuck on encryption. Could someone walk me through the process of how to encrypt a string using an AES 128bit key, CBC, PKCS7Padding, base64 format? I am new to encryption so bear with me here. I have posted questions in the past that relate to previous 3rd party libraries but none have worked for me. If someone could provide me sample code and briefly explain the process that would be greatly appreciated. Thanks.
For those who find errors and/or ommisions please either add a commwent and I will revise or edit this post directly.
AES 128bit key, CBC, PKCS7Padding, base64
AES: is an encryption method (Advanced Encryption Standard)
128 bit: the key length in bits (16 bytes).
CBC: an encryption mode (Cipher Block Chaining)
PKCS7Padding: adding bytes to data to be encrypted to make the data an exactly multiple of the block size
Base64: an encoding of 8-bit data into printable characters. Nothing to do with encryption but many times used with encryption
Block: AES encrypts data a block (16 bytes) at a time
iv: a seed value for certain encryption modes including CBC (initialization vector)
Needed for "AES, 128bit key, CBC, PKCS7Padding"
Encryption:
data: 8-bit bytes (any number)
key: 16 8-bit bytes (exactly)
iv: 16 8-bit bytes (exactly)
The encryption uses these inputs to create an encrypted output of 8-bit bytes with a length longer than the input due to padding to create an exact multiple of the block size. This will make the output data at least 1 byte longer than the input.
The output is raw bytes, that is not ASCII or a unicode encoding. In many cases the result must be printable characters and is Base64 encoded to achieve that. Base64 encoding makes the data longer.
Decryption:
If the data is in Base64 format decode it to raw bytes
data: 8-bit bytes
key: 16 8-bit bytes (exactly)
iv: 16 8-bit bytes (exactly)
The output will be raw 8-bit data bytes, exactly as were encrypted. If the encryption input data was ASCII or a unicode encoding the output will also be also.
That is all there is to it. The difficulties are getting the three items (data,key and iv) exactly the same.
Many crypto packages will accept keys and iv that are to short (or missing in the iv case) and pad them to the necessary length somehow. This is non-standard and causes problems. The easy way around this is to supply values that are exactly the correct length. These are data, that is 8-bit bytes, not strings, if you have strings convert then to data. When comparing the data, key and iv do it with hex dumps only. If you do this correxctly the encryption/decryption will just work.
There are a couple of other issues:
The key and iv must be known by both sides (encryption & decryption). The key is generally provided by one side to the other through a separate communications, perhaps even snail-mail. The iv also be shared and need not be secret, in fact it can be sent with the encrypted data.
The key needs to be good and of the correct length. In case it is a password a function is used to make it longer in a non-reversible manner. It should not be really fast. Current best practice is to use the PBKDF2 (Password Based Key Derivation Function) function with an iteration count. Older code tended to use a simple Hash (MD5 or SHA-*) but no longer should be used in new work.
Apple provided APIs for all this in Common Crypto for encryption and key derivation and NSData for Base64 encoding.
For a free PDF of an execelent book Handbook of Applied Cryptography
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need a regular expression for my Ruby on Rails application for the password field.
Any character or number or symbols is allowed except space.
If this is client-side validation in Javascript (or any language other than Ruby), this expression will match a string with no whitespace (\S) at least one character (+), no max:
^\S+$
Ruby is the only language that uses multi-line mode by default, so the start-of-line ^ and end-of-line $ behave differently (they match once per input, no matter how many lines). So, if you are validating the input in Ruby, you'd need to use \A for start-of-line and \Z for end-of-line.
\A\S+\Z
All except spaces, do you need to narrow the results a bit more than this?
/[^ ]+/
This is without minimum length (or rather, with minimum length 1):
^\S+$
With minimum length 8:
^\S{7}\S+$
or, if your regex engine supports it (don't know why it wouldn't):
^\S{8,}$