We’d like to remind Forumites to please avoid political debate on the Forum.
This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!
Any PHP Experts Here?
Comments
-
Sorry everyone didnt mean to rant yesterday but I feel like imj having a nervous breakdown and whereever I ask help even when ive submitted all my code im responded to in a negative way.
I feel ive made slight progress since yesterday. My array on the client side will now display this:
Letter:75
Value: 80
Letter: 121
Value: 126
Showing the +5 value to each ascii character now I just need to get it to automatically convert the new value eg in the first letter which is K(75) to P(80).
Currently I am getting it to display like this:$letter = chr(80); echo $letter; $letter = chr(126); echo $letter;
I understand I need to put this in a for loop but I cant seem to get it to work. Below is the code im currently using to do the encryption.$i=0; foreach ($arr as $letter) !! $value = ord($arr[$i]) +5; $letter = ord ($arr[$i]); //echo $letter; echo "Letter: " . $letter . "<br />"; echo "Value: " . $value. "<br />"; $i++; }
If anyone can advise if be so greatful2010 Wins: Benecol Bag For Life, £150 FCUK Voucher, Rimmel Foundation, L'oreal Mascara, £60 worth of hair products, £100 :j0 -
Are you trying to encrypt data from a browser (client side) and then decrypt it on a web server (server side)? If this is the case then you shouldn't use PHP to do your encryption as this runs server side only. You should use a client side tool like Javascript for this and then PHP for your decryption.
Your pseudo code for client side isread in String from user (html form) convert String into char array (Javascript from here) for each char in array add 5 to ascii value end for convert back to String submit form (use method='POST')You'll need to call you Javascript function from you 'action' parameter of your html form. e.g. 'action="encrypt(this)"' where encrypt is your Javascript function. The 'this' parameter is your form so you can use it to access your String parameter using the browser's DOM (google it and/or look and w3schools). For extra brownie points you should write your js function in a separate .js file and place it in a private directory of the web server so it is not publicly accessible. This will stop your web page users being able to suss out your encryption technique. Using POST to submit your form stops the form values being displayed in the browser's address bar.
Then on your server side PHP the pseudo code is this:read String value from http request convert String to char array for each char in array subtract 5 from ascii value end for convert to String then do whatever you need to do with it.Before I go on is this what you're trying to do or have I got the wrong idea?0 -
Hi Thanks for your reply,
Ive made some progress and now have my server reading in the encrypted string from my client but now I am having problems with the decryption.
Its performing the -5 function but still seems to be doing this off the original ASCII values. For some reason my copy and paste function wont work so I will try and post some code after ive restarted.
Thanks2010 Wins: Benecol Bag For Life, £150 FCUK Voucher, Rimmel Foundation, L'oreal Mascara, £60 worth of hair products, £100 :j0 -
$string = 'K,y,l,i,e,E,v,a,n,s'; $arr = explode(',', $string); $string = array($arr); for ($i=0; $i<sizeof($arr); $i++) !! $value = chr(ord($arr[$i])-5); $arr[$i] = $value; echo $arr[$i]; }2010 Wins: Benecol Bag For Life, £150 FCUK Voucher, Rimmel Foundation, L'oreal Mascara, £60 worth of hair products, £100 :j0 -
What you have there for decryption is fine. I assume the creation of your String and array is for testing then it's obvious why your result is 5 less than the original ascii because you're starting out with the original String.
I have simplified your code a little here as well. Note that you can implicitly treat strings as char arrays:
[php]
$string = "KylieEvans";
for ($i=0; $i<strlen($string); $i++) !!
$string[$i] = chr(ord($string[$i]) - 5);
}
echo $string;
[/php]This results in the String 'Ftgd`@q\in' being outputted to the browser.
Alright, so that's the decoder sorted out. Now what about the encoding of the String. Is this as I thought earlier, coming from your browser? So we'll have to do something similar but using Javascript instead of PHP?
Post what you've done so far with your client side encryption and we'll see what we can do with that.0 -
This won't help you much, but i remember writing this for my graphical calculator when i was doing my A Levels. rather than adding or subtracting a fixed value, i used a random number between 1 and 10..
I used a starting random seed number to ensure that the random sequence would always be consistently the same.
I managed to encrypt graphics files on my TI-83 calculator using that method.. ah, those were the days.0 -
Hello everyone thanks for all the help, been working hard and now got both my encryption and decryption working perfectly! Just trying to do it now from the input of a text box!
Thanks once again!
2010 Wins: Benecol Bag For Life, £150 FCUK Voucher, Rimmel Foundation, L'oreal Mascara, £60 worth of hair products, £100 :j0 -
This discussion has been closed.
Confirm your email address to Create Threads and Reply
Categories
- All Categories
- 352.2K Banking & Borrowing
- 253.6K Reduce Debt & Boost Income
- 454.3K Spending & Discounts
- 245.3K Work, Benefits & Business
- 601K Mortgages, Homes & Bills
- 177.5K Life & Family
- 259.1K Travel & Transport
- 1.5M Hobbies & Leisure
- 16K Discuss & Feedback
- 37.7K Read-Only Boards