|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
replacing text
I'm in the middle of writing a script that encrypts text. the way it works is it converts the text to binary and then changes the 1s to 0s and the 0s to 1s and converts it back to text again giving an encrypted version of the text. I can get the binary encoding/decoding to work but the bit i'm having trouble with is changing the 1s to 0s and the 0s to 1s. Any help on this would be greatly appreciated.
Thanks, -MarK |
|
#2
|
|||
|
|||
|
I would not reccomend encrypting text that way. What I would reccomend is to use a matrix. You use the pattern
1 = a 2 = b 3 = c 4 = d . . . 27 = A etc... what ever you want.... then you take the message such as Hello now convert it into the numbers 34 5 12 12 15 now put it into a matrix like so [34, 5, 12] [12, 15, 0] now you need a control matrix like so [1, 4, 5] [5, 4, 1] [4, 5, 1] now to encrypt it multiply the two matrix like so and you get [108, 220, 192] [87 , 108, 75 ] so the encrypted messege is: 108 220 192 87 108 75 now to decrypt the message you must put it back into a matrix [108, 220, 192] [87 , 108, 75 ] then to decrypt it you must multiply it by the control matrix's recipricl or inverse like so and you get [34, 5, 12] [12, 15, 0] so your message is now back to: 34 5 12 12 15 0 now go to your key what ever it may be... mine is up top and put the numbers with the letters 34 = H 5 = e 12 = l 12 = l 15 = o 0 = space (unless at end means nothing) so then you get: Hello vola. -Coke |
|
#3
|
|||
|
|||
|
yea, i've used that before, but this is just really a mess about i'd still like to be able to try getting my method to work. thanks for that though
|
|
#4
|
|||
|
|||
|
Well I can't help you with out any code.
-Coke |
|
#5
|
||||
|
||||
|
Iterate over your string. For each numeric character, add to a second string the abs() of that value minus one. This pushes ones back to zeroes and zeroes to abs(-1), which is 1. Some sample code:
PHP Code:
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
|
#6
|
||||
|
||||
|
Another option, of course, is to convert all ones to twos, then all zeroes to ones, then all twos to zeroes using any of the various string replacement functions. It'd be interesting to see which approach is faster.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > replacing text |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|