Jump to content


Check out our Community Blogs

Void

Member Since 13 Jun 2006
Offline Last Active Nov 18 2008 08:49 PM
-----

#331000 I got a job

Posted by Void on 30 April 2007 - 08:48 AM

Congrats! What is minimum wage at now?
  • -1


#320726 PHP Code: Simple Encryption Algorithm

Posted by Void on 18 October 2006 - 06:26 AM

This is a very simple Encryption Algorithm that uses the Caesar Shift Decoder (also called the Caesar Cipher).

The encryption is not limited to 25 characters though but is limited to the ASCII table moving each character a random amount of numbers forward.

Here is how it works:

1) Generate a Random Number


// Create a Random Generator
srand((double)microtime()*1000000); // Seed the Random Generator
$strCharNumber = rand(102,106); // Pics a number between 102 and 106


This code will be the variable for how many characters the encryption scheme will be moved forward. As you can see, it is between 102 and 106.

2) Add this character to our final string output


$strcode = chr($strCharNumber); // Add char to ending String


This allows us to grab that character and decrypt the entire string. This makes the code very unsecure as anyone that knows that is the decoding character can decode this message.

3) Encode the rest of the string. Lets say you received a g[/g] which is 103 ascii value. For each character you would get the ascii value and move it up 103 values in the ascii table.


// For Loop to convert each char into ascii then increase number
for ($i = 0; $i < strlen($name); $i++) {
$strChar = ord($name[$i]) + $strCharNumber;


4) In my code I also converted to hex but you can leave this step out if you like.


$strChar = bin2hex(chr($strChar));


[b]5)
Add the string to the final string and close the for loop.


$strcode = $strcode & $strChar;
}
?>


I've also attached a working copy of the PHP script. Let me know if you have any questions!

Attached Files


  • 1


#314678 Calling a form from another form

Posted by Void on 01 July 2006 - 06:41 AM

Managed C++ does not let you call a form by its form name. In C# you can do formname.function if it is a public function. You can call a perform click in C# just by the formname. In managed c++ it is a little different.

I had to write a callback function that sends messages just to call a previous form. Here is the code:

At the header I inserted:
//#include <windows.h>    // You could theoretically include Windows.h to get
                                     // all of the WM_ message values, but then your
                                     // basic .NET objects like MessageBox would no longer
                                     // function without a series of #ifndefs.

// Define WM_USER using the value in windows.h
#define WM_USER 0x0400
#define WM_PLAY 0x0401
#define WM_STOP 0x0402
#define WM_RESTART 0x0403
#define WM_PAUSE 0x0404
#define WM_EXITME 0x0405

// Define our custom message
#define MSG_CHILDTEXT (WM_USER+1) // Nothing
#define MSG_CHILDPLAY (WM_PLAY+1)
#define MSG_CHILDSTOP (WM_STOP+1)
#define MSG_CHILDRESTART (WM_RESTART+1)
#define MSG_CHILDPAUSE (WM_PAUSE+1)
#define MSG_CHILDEXIT (WM_EXITME+1)


Declare this in the new form (child form)
public: System::Windows::Forms::NativeWindow^ m_nwndParent;

Assign a handle in the parent form

//myFullTrans->StartClick = ionTimer::Form1::childForm_StartClick();
			 myFullTrans->m_nwndParent = gcnew System::Windows::Forms::NativeWindow ();
			 myFullTrans->m_nwndParent->AssignHandle (this->Handle);


Create a functino in the new form

private: System::Void msgToParentForm(int m)
		 {
			 				// Create a new windows message object
			   System::Windows::Forms::Message msgTextSetter;

			   // Set the message type to our custom message
			   msgTextSetter.Msg = m;

			   // Tell the NativeWindow object to send the message
			   // to the default WndProc of the window whose handle
			   // it represents
			   m_nwndParent->DefWndProc (msgTextSetter);
		 }


Call the function
msgToParentForm(MSG_CHILDPAUSE);

  • -1


#314498 Storing Binary

Posted by Void on 27 June 2006 - 07:06 AM

NeedHelp, I've done this before. The table needs to be a blob.
This is the code to insert into DB

add.php (Where the user inserts data to be submitted and browses for pictures)

<form enctype="multipart/form-data" action="insert.php" method="POST" name=changer>
<input type="hidden" name="MAX_FILE_SIZE" value="102400">
<input type="file" name="photo" accept="image/jpeg">
<input type="Submit" value="Submit">


insert.php file

<?php
// Connect to the DB somwhere up here

// Read our photo
$**="";
if (!empty($_FILES['photo']['name'])) {
$** = addslashes(FormatImage($_FILES['photo']['name'], $_FILES['photo']['tmp_name']));
}

$query = "INSERT INTO name (tb_name) VALUES ('$**')";
$results = mysql_query($query) or die ("Error " . mysql_error());
mysql_close();

// This function formats the image and can resize if desired
function FormatImage($sPhotoFileName, $sTempFileName) {
//$sPhotoFileName = $_FILES['photo']['name']; // get client side file name

if ($sPhotoFileName) // file uploaded
{ $aFileNameParts = explode(".", $sPhotoFileName);
$sFileExtension = end($aFileNameParts); // part behind last dot
if ($sFileExtension != "jpg"
&& $sFileExtension != "JPEG"
&& $sFileExtension != "JPG")
{ die ("Choose a JPG for the photo");
}
$nPhotoSize = $_FILES['photo']['size']; // size of uploaded file
if ($nPhotoSize == 0)
{ die ("Sorry. The upload of $sPhotoFileName has failed.
Search a photo smaller than 100K, using the button.");
}
if ($nPhotoSize > 102400)
{ die ("Sorry.
The file $sPhotoFileName is larger than 100K.
Advice: reduce the photo using a drawing tool.");
}
}

// read photo
//$sTempFileName = $_FILES['photo']['tmp_name']; // temporary file at server side
$oTempFile = fopen($sTempFileName, "r");
$sBinaryPhoto = fread($oTempFile, fileSize($sTempFileName));

// Try to read image
$nOldErrorReporting = error_reporting(E_ALL & ~(E_WARNING)); // ingore warnings
$oSourceImage = imagecreatefromstring($sBinaryPhoto); // try to create image
//error_reporting($nOldErrorReporting);

if (!$oSourceImage) // error, image is not a valid jpg
{ die ("Sorry.
It was not possible to read photo $sPhotoFileName.
Choose another photo in JPG format.");
}

$nWidth = imagesx($oSourceImage); // get original source image width
$nHeight = imagesy($oSourceImage); // and height

// create small thumbnail
$nDestinationWidth = $nWidth;
$nDestinationHeight = $nHeight;
//$oDestinationImage = imagecreatetruecolor($nDestinationWidth, $nDestinationHeight);
$oDestinationImage = imagecreate($nDestinationWidth, $nDestinationHeight);

// below resizes the image
imagecopyresized(
$oDestinationImage, $oSourceImage,
0, 0, 0, 0,
$nDestinationWidth, $nDestinationHeight,
$nWidth, $nHeight); // resize the image


ob_start(); // Start capturing stdout.
imageJPEG($oDestinationImage); // As though output to browser.
$sBinaryThumbnail = ob_get_contents(); // the raw jpeg image data.
ob_end_clean(); // Dump the stdout so it does not screw other output.

// Return our image
return $sBinaryThumbnail;
}

?>

  • 1


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download