Wednesday, April 14, 2010

PHP Tutorial - Repeat Echo

Official CP309's Tutorials
PHP Tutorial - Repeat Echo

Want to repeat echo without using for(); ? Heres a function i made for it!


function echo_repeat($whattoecho, $howmany = 1){
 for($i=1;$i<=$howmany;$i++) echo($whattoecho);
}

Heres how to use it:

echo_repeat(what to echo, how many times);

if you want only one time, you can use this:

echo_repeat(what to echo);

or

echo(what to echo);

Have Fun!

http://pastebin.com/9Kz19vRG

Saturday, April 3, 2010

Math Quiz Bot

<?php
/*


    Math Question
    By CP309


     GNU License:
    
   
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
   
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
   
     You should have received a copy of the GNU General Public License
     along with this program. If not, search it at the internet and read
     it.


*/


//// Variables ////
$score = 1;
$wrscore = 1;
$qs = 1;
///////////////////

function questionask($question, $answer){
global $score;
global $wrscore;
global $qs;
$qs++;
echo($question . "\n");
echo("What is your answer? \n");
$ans = trim(fgets(STDIN));
if($ans==$answer){
echo("Correct! Your answer is $answer!\n");
$score++;
return $score;
} else {
echo("Wrong! The Answer is $answer !\n");
$wrscore++;
return $wrscore;
}
return $qs;
}

function add($v1, $v2){
$answerd = $v1 + $v2;
return $answerd;
}
function subtract($v1, $v2){
$answerd = $v1 - $v2;
return $answerd;
}
function multiply($v1, $v2){
$answerd = $v1 * $v2;
return $answerd;
}

function squareroot($s){
$ansz = $s * $s;
return $ansz;
}


echo("Welcome to Math Quiz Bot!\n Made by Kiko Perez! \n\n");

questionask("What is the Square root of " . squareroot(8) . "?", "8");
questionask("What is the Square root of " . squareroot(99) . "?", "99");
questionask("What is the Square root of " . squareroot(12) . "?", "12");
questionask("What is the Square root of " . squareroot(45) . "?", "45");
questionask("What is the Square root of " . squareroot(86) . "?", "86");
questionask("What is the Square root of " . squareroot(83) . "?", "83");
questionask("What is the 7 x 8?", multiply(7, 8));
questionask("What is the 9 x 5?", multiply(9, 5));
questionask("What is the 5 x 6?", multiply(5, 6));
questionask("What is the 5 x 2?", multiply(5, 2));
questionask("What is the 5 x 7?", multiply(5, 7));
questionask("What is the 4 x 10?", multiply(4, 10));
questionask("What is the 3 x 4?", multiply(3, 4));
questionask("What is the 7 x 2?", multiply(7, 2));
questionask("What is the 9 + 7?", add(7, 8));
questionask("What is the 9 + 5?", add(9, 5));
questionask("What is the 5 + 6?", add(5, 6));
questionask("What is the 5 + 2?", add(5, 2));
questionask("What is the 5 + 7?", add(5, 7));
questionask("What is the 4 + 10?", add(4, 10));
questionask("What is the 3 + 4?", add(3, 4));
questionask("What is the 7 + 2?", add(7, 2));
questionask("What is the 10 - 8?", subtract(10, 8));
questionask("What is the 9 - 5?", subtract(9, 5));
questionask("What is the 5 - 2?", subtract(5, 2));
questionask("What is the 120 - 56?", subtract(120, 56));
questionask("What is the 5643 - 546?", subtract(5643, 546));
questionask("What is the 123 - 10?", subtract(123, 10));
questionask("What is the 56 - 35?", subtract(56, 35));



echo("You have answered $qs Questions!\n You got $score corrects!\n You got $wrscore Mistakes!\n");
sleep(2);
echo("Thanks for taking the quiz!\n");
sleep(5);
exit;






?>

YOU MAY DISTRIUTE THIS TO ANYONE ELSE, PLEASE DO NOT REMOVE CREDIT OR ILL DELETE THIS

MD4 Explanation

(Source from Wikipedia.org)

MD4 (Message-Digest algorithm 4) is a message digest algorithm (the fourth in a series) designed by Professor Ronald Rivest of MIT in 1990. It implements a cryptographic hash function for use in message integrity checks. The digest length is 128 bits. The algorithm has influenced later designs, such as the MD5, SHA and RIPEMD algorithms. MD4 is also used to compute NT-hash password digests on Microsoft Windows NT, XP, Vista and 7[citation needed].
One MD4 operation : MD4 consists of 48 of these operations, grouped in three rounds of 16 operations. F is a nonlinear function; one function is used in each round. Mi denotes a 32-bit block of the message input, and Ki denotes a 32-bit constant, different for each operation.
Weaknesses in MD4 were demonstrated by Den Boer and Bosselaers in a paper published in 1991. The first collision attack was found by Hans Dobbertin in 1996. In August 2004, Wang et al. found a very efficient collision attack, alongside attacks on later hash function designs in the MD4/MD5/SHA/RIPEMD family. This result was improved later by Sasaki et al., and generating a collision is now as cheap as verifying it (a few microseconds).
A variant of MD4 is used in the ed2k URI scheme to provide a unique indentifier for a file in the popular eDonkey2000 / eMule P2P networks. MD4 is also used by the rsync protocol.

MD5 explanation

(Source from wikipedia.org)

In cryptography, MD5 (Message-Digest algorithm 5) is a widely used cryptographic hash function with a 128-bit hash value. Specified in RFC 1321, MD5 has been employed in a wide variety of security applications, and is also commonly used to check the integrity of files. However, it has been shown that MD5 is not collision resistant;[1] as such, MD5 is not suitable for applications like SSL certificates or digital signatures that rely on this property. An MD5 hash is typically expressed as a 32-digit hexadecimal number.
MD5 was designed by Ron Rivest in 1991 to replace an earlier hash function, MD4. In 1996, a flaw was found with the design of MD5. While it was not a clearly fatal weakness, cryptographers began recommending the use of other algorithms, such as SHA-1 (which has since been found also to be vulnerable). In 2004, more serious flaws were discovered, making further use of the algorithm for security purposes questionable.[2][3] In 2007 a group of researchers described how to create a pair of files that share the same MD5 checksum.[4] In an attack on MD5 published in December 2008, a group of researchers used this technique to fake SSL certificate validity.[5][6] US-CERT of the U. S. Department of Homeland Security said MD5 "should be considered cryptographically broken and unsuitable for further use,"[7] and most U.S. government applications will be required to move to the SHA-2 family of hash functions after 2010.[8]

Dynamic Image with PHP

<?php 

function addText($image, $text, $x, $y, $font, $color, $fontsize){
$txt = imagettftext($image, $fontsize, 0, $x, $y, $color, $font, $text);
return $txt;
}

function createImage($width,$height){
$im = ImageCreate($width, $height);
return $im;
}

function backgroundColor($color){
$imf = ImageFill($image, 0, 0, $color);
return $imf;
}

function setImageType($image, $type){

    //Tell the browser what kind of file is come in 
    header("Content-Type: image/$type");

if($type=="jpeg") ImageJpeg($image);
elseif($type=="png") ImagePng($image);
elseif($type=="jpeg") ImageJpeg($image);
elseif($type=="gif") ImageGif($image); 
}
   
function freeImage($image){
    ImageDestroy($image);
}


 


    //We are making three colors, white, black and gray
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, 0, 0, 0);
    $grey = ImageColorAllocate($image, 204, 204, 204);




?>

MD5 Script

It is easy to md5 some pass using php by doing this

<?php

function getMD5($password){
$md5pass = MD5($password);
return $md5pass
}

?>