How can I set up a 14-digit natural number password without being guessed?
Original problem address: http://www.zhihu.com/question/36989779
Problem description
An APP is displayed with a common calculator. After you enter a specific number, you can view your saved secret images and files. How can I avoid the bear child from pressing this number or the answer is this number when using this calculator? Note: The number is less than 15 digits and cannot start with 0. It does not contain letters, symbols, or decimal places.
My answer
According to the requirements of the subject, this is a password generation and management problem. We need to follow the following principles:
Confidential cannot use passwords that are too simple and easy to guess. The length cannot be too short, and the number must be too many. The number cannot be too meaningful (for example, the subject's birthday, employee ID/student ID, or even ID card numbers), which must be random. Otherwise, attackers may easily crack the code by using a good dictionary. The most effective way to deal with brute-force cracking is to increase the password length. Therefore, the maximum number of 14 characters mentioned by the subject is the length of the target password. Accessible must be able to easily find the tool to generate. In addition, according to the confidential principle, after the tool is generated, it cannot simply copy the White Paper or the memorandum that comes with the system, otherwise, the bear child will find it in minutes and then take it off, but it is too difficult to remember 14 digits directly. Therefore, we can consider encrypting the password for record and remembering the encryption algorithm and key, alternatively, you can use one or more remembered objects as the key input, and the encryption result is directly used as the generated password.
To sum up, a feasible idea is to generate a pseudo-random number as a password.
Solution 1
Take a string or number that can be remembered, use the hash function to calculate the hash value, and take the first 14 digits as the output
For example, you can set this parameter to 60354186872526.
For example, this parameter can be set to 32993841519355.
If you think the generated number is too clever, you can change the familiar word phrase and calculate it again until the production is satisfactory.
Solution 2
Find an image, such as your CP's homophone image. Use MD2 encoding to generate a digital fingerprint as the random seed, and use this seed to generate a 14-bit random number as the password.
If you need this password, use the original image and follow this process.
We can define a function in advance:
ApplyForPassword[x_] := {SeedRandom[Hash[Import[x], "MD2"]]; RandomInteger[{10^14, 10^15 - 1}] }
In this way, call ApplyForPassword ["path"] to obtain the 14-bit pseudo-random password (path is the image path string)
Solution 3
Randomly generate a 14-digit natural number as the password. Use Steganography to disguise the password as a very common image and restore the information when you need to use the password. For example, there is a completed implicit write code solution for reference:
Camouflage process:
Recovery Process:
These implicit write operations can also be encapsulated into two functions. Camouflage function (the first parameter is the carrier image, and the second parameter is the ciphertext ):
StegCover[Carrier_Image, text_] := Block[{CarrierData, TruncatedCarrier, pixelChannels, SecretBits, LifeLength, SecretData}, CarrierData = ImageData[Carrier, "Byte"]; TruncatedCarrier = BitAnd[CarrierData, 2^^11111110]; pixelChannels = Apply[Times, Dimensions[CarrierData]]; SecretBits = Flatten[IntegerDigits[ ToCharacterCode[ ToString[text, InputForm, CharacterEncoding -> "ASCII"]], 2, 8]]; LifeLength = IntegerDigits[Length[SecretBits], 2, 48]; SecretData = Fold[Partition, PadRight[Join[LifeLength, SecretBits], pixelChannels], Reverse@Rest[Dimensions[CarrierData]]]; Image[TruncatedCarrier + SecretData, "Byte"]]
Restoration function (the parameter is a disguised image ):
StegUncover[CoverImage_Image] := Block[{SecretData, LifeLength, secretBytes}, SecretData = Flatten[BitAnd[ImageData[CoverImage, "Byte"], 1]]; LifeLength = FromDigits[Take[SecretData, 48], 2]; secretBytes = Partition[Take[Drop[SecretData, 48], LifeLength], 8]; ToExpression[ FromCharacterCode[FromDigits[#, 2] & /@ Take[secretBytes]]] ]
In this way, you can directly call StegCover and StegUncover to hide any text (or other content) in any image.
Of course, this solution also has a major defect, that is, it reduces the resource utilization rate. For example, the color illustration of a text in the seventh volume of the Chinese language of the Jiangsu Education Edition is 508*715 pixels, with three color channels: RGB, in our method, we can completely store 508*715*3/8 = 136207 characters. Here, if we only store 14-bit passwords (+ String termination identifier '\ 0 ', A total of 15 char space ciphertext) is a serious waste. The Basic Law of The People's Republic of China (Douban) of the Hong Kong Special Administrative Region contains a total of 55983 characters. It is assumed that all the characters are Chinese characters (ASCII Code) of 2 char lengths, and only 111966 characters are needed, it is also used to store 6 bytes in length, and the remaining 24235 bytes are free. In this case, our solution seems to be a bit cool-killing tool.
It may be a problem. The advantage of this solution is that it can hide a large amount of information and put a gettypolicgaddress into the image without any feeling. The generated camouflage images can also be stored as png or other lossless images to exchange information on the network or other platforms.
An egg. Guess what this ghost has hidden?