Hi, anybody have sockets programming tutorial with PHP?
What help you need?
Can u please help me?
Where is the code?
AWS
Happy for u. 👍
It’s urgent.
To achieve textbox and button you have to use html.
For encrypt-decrypt, you can use php
// enter the word to be encrypted
$wordToBeEncrypted = “abcd”;
echo “The Word to be encrypted will be $wordToBeEncrypted <br> <br>”;
// break the word into an array
$lettersOfWord = str_split($wordToBeEncrypted);
// uncomment the code below to see the array that contains the letters of the chosen word
// echo “<pre>” . print_r($lettersOfWord) . “</pre>”;
// create an array that will contain of all of the letters that will be used for encryption
$array = array(‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’);
// create and array that will hold the encrypted letters
$encryptedArrayOfLetters = array();
// use foreach loop to iterate through the array of letters that has been broken down from the $wordToBeEncrypted
foreach ($lettersOfWord as $row) {
$letter = $row; // this contains the letter of the wordToBeEncrypted
// find the index of the letter that is in the $array variable
$index = array_search($letter, $array, true);
// echo “$index -> $letter <br>”; -> uncomment me to see the index with their letter respectively
// general algo for encrypting
// the first letter of the wordToBeEncrypted is a; which is at index zero.
// just incriment the index by 3 which will return the letter “d”
// general algo will be implemented under this comment
$encodedLetter = $array[$index + 3];
// append the encoded letter into the array
array_push($encryptedArrayOfLetters, $encodedLetter);
}
// the process of encryption is complete its now time to assemble the letters in the appended array
$encodedWord = join(“”, $encryptedArrayOfLetters);
echo “The encrypted word will be: $encodedWord <br>”;
// time for decoding
// use the encoded word for decoding
// break the encoded word into an array
$brokenEncodedWord = str_split($encodedWord);
// create an array to store the letters. the decoded letters will be appended in this array
$decodedArrayOfLetters = array();
foreach ($brokenEncodedWord as $row) {
$decodedLetter = $row;
// decrement the index to turn back the decoded letter
# find the index of the letter in the $array variable
$decodedIndex = array_search($decodedLetter, $array, true);
// decrement the index to turn back the decoded letter into it’s original letter.
$originalLetter = $array[$decodedIndex – 3];
// append the decoded letter into the decoded array of letters variable
array_push($decodedArrayOfLetters, $originalLetter);
}
// assemble the decoded array of letters array into a word
$decodedWord = join(”, $decodedArrayOfLetters);
echo “<br> The decoded word will be: $decodedWord”;
// write into a text file
$myfile = fopen(“newfile.txt”, “w”) or die(“Unable to open file!”);
$txt = “The Word to be encrypted will be $wordToBeEncrypted n The encrypted word will be: $encodedWord n”;
fwrite($myfile, $txt);
$txt = “The decoded word will be: $decodedWord n”;
fwrite($myfile, $txt);
fclose($myfile);
Use required attribute….