Jump to content

  • Log In with Google      Sign In   
  • Create Account


Charabis

Member Since 08 Apr 2006
Offline Last Active Apr 28 2013 04:31 PM
-----

Topics I've Started

Javascript Equivalent of C# MD5

06 February 2012 - 01:36 PM

Actually, it's Javascript, but that's a different matter entirely. I have the following C# code that simply takes a string and encodes it:

public string CalculateMD5Unicode(string input)
{
	 // step 1, calculate MD5 hash from input
	 MD5 md5 = System.Security.Cryptography.MD5.Create();
	 byte[] inputBytes = System.Text.Encoding.Unicode.GetBytes(input);

	 byte[] hash = md5.ComputeHash(inputBytes);
	
	 return Convert.ToBase64String(hash);
}

Now I need to duplicate the output of this code in Javascript. So far, I've gotten it to where the same bytes are extracted:

function Process(str)
{

	var ch;
	var bytes = [];
	for(var i = 0; i < str.length; i++)
	{
		ch = str.charCodeAt(i);
		bytes.push(ch & 0xFF, ch>>>8);
	}
}

But I've hit a bit of a snag in trying to get the MD5 values to match. Specifically, this will be called from an HTML form to generate the same data currently being generated in the compiled C# program.

And yes, I know MD5 hashing is not terribly secure for doing passwords and what-not, but this is only going to be used until this gets closer to being released. Taking a lot of work to convince the guys in charge to buy an SSL certificate as they don't see it as being needed for testing. Isn't it fun to work for people who just don't know how to do...well anything Posted Image

Loading PNG In PHP And Returning It To C#

09 January 2012 - 04:43 PM

I'm working on a project that requires an array of textures. I'm looking to get the assets through PHP to avoid allowing direct access to them, but am having trouble getting them to return in a meaningful way. This is what I've built so far on the PHP side:

<?php
if(filter_has_var(INPUT_POST, "merchant") && filter_has_var(INPUT_POST, "test"))
{
$merchant = filter_input(INPUT_POST, "merchant", FILTER_SANITIZE_STRING);
$test = filter_input(INPUT_POST, "test", FILTER_SANITIZE_STRING);
}
else
{
die ("DataMissing");
}
$data_location = $_SERVER['DOCUMENT_ROOT'] . "/" . $merchant;
$arr = array();
if (is_dir($data_location))
{
    $dir = opendir($data_location) or die("Couldn't access directory!");
    while (($file = readdir($dir)) !== false)
    {
  $arr[] = file_get_contents($file);
    }
    echo $arr;
}
else
{
// Need to create it
mkdir($data_location, 0700) or die("Couldn't create " . $data_location);
echo "Empty";
}
?>

Creating the directory works fine, however I'm not seeming to get what I'd expect back to the C# program which calls it. In fact, with nothing in the folder, I seem to get back the string "Array". Needless to say, that's not what I expect or want!

Now this is weird

07 January 2008 - 06:51 PM

Below are two snippets of code. The first works, but the second is claiming that "Object reference not set to an instance of an object." As near as I can tell, they're effectively identical, so why does the second one not work? They're written in Visual Basic 2005, and are part of my final project for Intro to Programming. Sad thing is I showed the teacher and he wasn't sure what I did in the first one!
            Dim picButton As System.Windows.Forms.PictureBox
            Dim lstButton As System.Windows.Forms.ListBox
            Do Until Placement > 26
                If Placement < 9 Then
                    picButton = Me.Controls("picSkill0" & (Placement + 1))
                    lstButton = Me.Controls("lstSkill0" & (Placement + 1))
                Else
                    picButton = Me.Controls("picSkill" & (Placement + 1))
                    lstButton = Me.Controls("lstSkill" & (Placement + 1))
                End If
                LoadButtonInfo(0, Placement, picButton, lstButton)
                Placement += 1
            Loop
        Dim BoxRef As System.Windows.Forms.NumericUpDown
        BoxRef = Me.Controls("numAccuracy")
        AttributeChange(0, BoxRef)
Ideas? I'm at a total loss, and searching for hours on the web has yielded nothing relating to this except mention of using something like "Set Boxref =" etc. Problem is when I try to prefix that line with Set, Visual Basic discards it again.

SDL With OpenGL rendering problem

18 March 2007 - 09:03 AM

I was trying to load a PNG file to display on the screen. However, the following code just makes a largish, white block that doesn't even fill the screen. Both the image and the screen resolution are set to 640x480 resolution. Here's the code snippets:

FROM INIT:

	// Initialize SDL
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) &lt; 0)
	{
		cout &lt;&lt; "Couldn't initialize SDL!  " &lt;&lt; SDL_GetError() &lt;&lt; '\n';
		return 0;
	}
	atexit (SDL_Quit);						// Have SDL clean itself up when the program exits
	// Set OpenGL attributes
	if (SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1) == -1)		// Turn on double-buffering
	{																// FAILED!!
		cout &lt;&lt; "Unable to turn on double buffer!  " &lt;&lt; SDL_GetError() &lt;&lt; '\n';
		return 0;
	}
	/* MAY BE NEEDED FOR NON-MAC SYSTEMS
	if (SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 8)) == -1)		// Turn on double-buffering
	{																// FAILED!!
		cout &lt;&lt; "Unable to set red component's buffer size!  " &lt;&lt; SDL_GetError() &lt;&lt; '\n';
		return 0;
	}
	if (SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 1)) == -1)		// Turn on double-buffering
	{																// FAILED!!
		cout &lt;&lt; "Unable to set green component's buffer size!  " &lt;&lt; SDL_GetError() &lt;&lt; '\n';
		return 0;
	}
	if (SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 1)) == -1)		// Turn on double-buffering
	{																// FAILED!!
		cout &lt;&lt; "Unable to set blue component's buffer size!  " &lt;&lt; SDL_GetError() &lt;&lt; '\n';
		return 0;
	}
	if (SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 1)) == -1)		// Turn on double-buffering
	{																// FAILED!!
		cout &lt;&lt; "Unable to set alpha component's buffer size!  " &lt;&lt; SDL_GetError() &lt;&lt; '\n';
		return 0;
	}
	*/
	
	// Set up drawing context
	gp_screen = SDL_SetVideoMode (gi_width, gi_height, 32, SDL_OPENGL | SDL_FULLSCREEN);
	if (!gp_screen)
	{
		cout &lt;&lt; "Unable to set resolution to " &lt;&lt; gi_width &lt;&lt; "x" &lt;&lt; gi_height &lt;&lt; ": " &lt;&lt; SDL_GetError() &lt;&lt; '\n';
		return 0;
	}
	SDL_WM_SetCaption ("Tringus", NULL);
	// Prep Open GL
	glClearColor (0.0, 0.0, 0.0, 0.0);		// Set clear color to BLACK
	// Set OpenGL Projection Matrix
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0.0, gi_width, gi_height, 0.0, -1.0, 1.0);
	// Initialize Modelview Matrix
	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity();
	// Ensure Viewport is set to the entire window
	glViewport (0, 0, gi_width, gi_height);
	if (glGetError() != GL_NO_ERROR)		// Check for any errors
	{
		cout &lt;&lt; "Error setting up OpenGL!  " &lt;&lt; glGetError() &lt;&lt; '\n';
		return 0;
	}
	
	// Initialize SDL_Mixer
	if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 1, 4096) == -1)
	{
		cout &lt;&lt; "Unable to initialize SDL Mixer!  " &lt;&lt; SDL_GetError() &lt;&lt; '\n';
		return 0;
	}

	return 1;


FROM MAIN :
	GLuint textures[2];
	if (!initGame())
		return 1;
	Resource files[] =	{
							{1, "graphics/vbslogo.png"},
							{1, "graphics/presents.png"},
							{2, "sound/howl.wav"}
						};	if (checkResources (files, 3))
	{
		cout &lt;&lt; "Please reinstall software to restore the missing resources.\n";
		return 1;
	}
	// Load/check studio screen
	SDL_Surface* image = IMG_Load("graphics/vbslogo.png");
	if (!image)
	{
		cout &lt;&lt; "Unable to load studio graphic!  " &lt;&lt; SDL_GetError() &lt;&lt; '\n';
		return 1;
	}
	glGenTextures (2, textures);
	glBindTexture (GL_TEXTURE_2D, textures[0]);
	glTexImage2D (GL_TEXTURE_2D, 0, 3, image-&gt;w, image-&gt;h, 0, GL_RGB, GL_UNSIGNED_BYTE, image-&gt;pixels);
	SDL_FreeSurface(image);
	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	// STUDIO SCREEN READY TO GO!!!
	
	glBindTexture (GL_TEXTURE_2D, textures[1]);
	glTexImage2D (GL_TEXTURE_2D, 0, 3, image-&gt;w, image-&gt;h, 0, GL_RGB, GL_UNSIGNED_BYTE, image-&gt;pixels);

	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	// PRESENTATION SCREEN READY TO GO!!
	
	// Load audio file
	Mix_Chunk* sound = Mix_LoadWAV("sound/howl.wav");
	if (!sound)
	{
		cout &lt;&lt; "Unable to load sound effect!  " &lt;&lt; SDL_GetError() &lt;&lt; '\n';
		return 1;
	}
	Mix_AllocateChannels (1);					// Only need 1 channel for now
	Mix_VolumeChunk (sound, MIX_MAX_VOLUME);	// Set chunk to max volume
	if (Mix_PlayChannel(-1, sound, 0) == -1)
	{
		cout &lt;&lt; "Unable to play sound! " &lt;&lt; SDL_GetError() &lt;&lt; '\n';
		return 1;
	}
	// Turn 2D-Texturing on
	glEnable (GL_TEXTURE_2D);								// Turn 2-d texturing on
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear the buffers (Screen to black)
	glBindTexture (GL_TEXTURE_2D, textures[0]);				// Make Studio texture active
	glBegin (GL_QUADS);										// START DRAWING!!!
		glTexCoord2i (0, 0);
		glVertex2i (0, 0);
		
		glTexCoord2i (1, 0);
		glVertex2i (gi_width, 0);
		
		glTexCoord2i (1, 1);
		glVertex2i (gi_width, gi_height);
		
		glTexCoord2i (0, 1);
		glVertex2i (0, gi_height);
	glEnd();
	SDL_GL_SwapBuffers();



Now we can play "Find the stupid mistake I made." I'm sure I did something monumentally stupid to such a basic idea to make it not work, but darned if I can find it after 3 days of trying to! ----------------------------------------

Upgrading membership

09 March 2007 - 07:16 AM

Just upgraded using PayPal, and was wondering how long it takes for it to kick in [smile]. Figure I needed to take a concrete step considering how many 'false starts' I've had in the past [wink]

PARTNERS