I have just uploaded a single file to github which computes cosine similarity of two files. Cosine similarity is a widely used similarity measure of two texts. This simple code computes cosine similarity of two text files given as parameters. To use this, php-cli (PHP command line interpreter) must be working. The output is written to the STDOUT. I have made the cosine similarity code work in PHP. I have not implemented all of the code. The code is developed using the ideas and piece of codes in various web sites. I used this code in identification of topics of a microblog post set which was introduced in this post. Usage: php computeCosine.php file1 file2

The most common function used in Ethereum application development is the Keccak256 hashing. Keccak256 is used for Ethereum message signing, obtaining the wallet address given a public key, determining smart contract address and determining the function selector of smart contract to be provided as data in transactions given a function prototype (like in ABI encoding). I have looked around and could not find a useful implementation for this. They are either unfinished like this one or too complicated to use like this one, or this one.
All I need is a simple keccak256() function that returns keccak-256 of a hex encoded string. So I decided to do it for myself. I looked around a bit and found a clear C program in this page. All I need is to make this code work in PHP. Luckily PHP has a mechanism to extent its functionality. I followed the guide here. Then I obtained a working keccak256 function.
In this github page, I published the codes to be used by anyone interested.
Before installation, PHP developer files must be installed. To install keccak256() functionality:
  • git clone https://github.com/RnDevelover/Keccak256PHP.git
  • cd Keccak256PHP
  • phpize
  • ./configure --enable-keccak256
  • make
  • copy modules/keccak256.so to your php extension directory.
  • enable extension by adding extension=keccak256.so to your php.ini
Usage:
$a="cc"; // Hex encoded string. All characters are [0-9a-fA-F].
$hash=keccak256($a);
echo $hash; // Hex encoded hash.

This function returns a string of hex encoded 256 bit data (64 characters where each two character indicates one byte).
Next Post Newer Posts Previous Post Older Posts Home