Archive for November, 2009

WordPress admin login

Monday, November 30th, 2009

After reading on the SANS website about a dirty process of using distributed wordpress as from here. One of the ways to make sure that the user cannot keep on trying to use brute force to access your site is to set the password randomly, I use this website pctools which comes up with a very nice password for you.

Also within the brute force attach they are using the username of admin to try and login so you could change the admin username.

UPDATE wp_users SET user_login = '<insert name here>' WHERE user_login = 'admin';

Of course if you have setup the pre table name of wp_ instead it would be users table name.

Multiplication

Friday, November 27th, 2009

Whilst I was understanding the bits structure of binary values I did come across the page from here about how to do multiplication with binary values and thought that I might as well do it in c++ to understand abit more about the process.

The main part from that page above is

Rules of Binary Multiplication

  • 0 x 0 = 0
  • 0 x 1 = 0
  • 1 x 0 = 0
  • 1 x 1 = 1, and no carry or borrow bits

For example,

00101001 × 00000110 = 11110110 0  0  1  0  1  0  0  1 = 41(base 10)
× 0  0  0  0  0  1  1  0

= 6(base 10)
0  0  0  0  0  0  0  0
0  0  1  0  1  0  0  1
0  0  1  0  1  0  0  1

0  0  1  1  1  1  0  1  1  0 = 246(base 10)
00010111 × 00000011 = 01000101 0  0  0  1  0  1  1  1 = 23(base 10)
× 0  0  0  0  0  0  1  1

= 3(base 10)
1  1  1  1  1 carries
0  0  0  1  0  1  1  1
0  0  0  1  0  1  1  1

0  0  1  0  0  0  1  0  1 = 69(base 10)

Of which I have tried to implement in the below.

#include <iostream>
#include <bitset>
#include <limits>
 
using namespace std;
 
/* mutiplication using the binary shift operator */
int multiplication(int mul, int by)
{
    int result = 0;
    if (by > 0)
    {
        // mulitiply by (mulby) comparsion for when to add a shifted value to the result.
        // moveby, how many shifts left to shift by if there is a match.
        int mulby = 2, moveby = 1;
        while (by >= mulby)
        {
            cout << "by      = " << bitset<numeric_limits<short>::digits>(by) << endl;
            cout << "mulby = " << bitset<numeric_limits<short>::digits>(mulby) << endl;
            // bitwise add and if it is the same value as the mulby then add to the result.
            if ((by & mulby) == mulby) {
                cout << "+ result= " << bitset<numeric_limits<short>::digits>((mul << moveby)) << endl;
                result += mul << moveby;
                cout << "result   = " << bitset<numeric_limits<short>::digits>(result) << endl;
            }
            mulby = mulby << 1; // the next test if the bits values are the same.
            moveby++;           // move the result by
        }
        // and if there is a modulus of 1 from 2 then the value was odd.
        if (by % 2 == 1)
        {
            result += mul;
        }
        cout << "end result = " << bitset<numeric_limits<short>::digits>(result) << endl;
    }
    return result;
}
 
int main ()
{
  cout << multiplication(6,7) << endl;
  return 0;
}

and the output would be

by           = 000000000000111
mulby        = 000000000000010
+ result     = 000000000001100
result       = 000000000001100
by           = 000000000000111
mulby        = 000000000000100
+ result     = 000000000011000
result       = 000000000100100
end result   = 000000000101010
42

which is correct

6 * 7 = 42

Call a function

Monday, November 23rd, 2009

Lets just say that you are writing a template program and you want to add into a array of function calls, which you can add to as well on-the-fly. Within PHP you can use a function called call_user_func which allows you to call a function using a stringed parameter in the first parameter and the next parameter(s) (if you wish to pass more than one parameter) is next. Hopefully the below will demonstrate better.

<?php
  function test($var)
  {
    echo "test : " . $var;
  }
 
  function example($var)
  {
    echo "example : " . $var;
  }
 
  $funarr = array(array("test", "codingfriends"), array("example", "was here"));
 
  foreach ($funarr as $funarr_call)
  {
    call_user_func($funarr_call[0], $funarr_call[1]);
    echo "<br/>";
  }
?>

and the output would be

test : codingfriends
example : was here

Conditions – true or false

Friday, November 20th, 2009

When you want to do a test against true or false with a integer value. Basically 0 is false and anything else is true, as demonstrated below.

#include <stdlib.h>
#include <iostream>
 
using namespace std;
 
int main()
{
  for (int i = -10; i < 10; i++)
  {
      if (i) 
	  cout << "true " << i << endl;
      else
	  cout << "false " << i << endl;
  }
}

and the output of this is, the true/false values is after the if statement.

true -10
true -9
true -8
true -7
true -6
true -5
true -4
true -3
true -2
true -1
false 0
true 1
true 2
true 3
true 4
true 5
true 6
true 7
true 8
true 9