Everything , Everywhere
ALL AT ONCE
Waaay way past due in writing a fully comprehensive — -article, blog? Whichever fits. I decided to fully commit myself to finish or rather polish up on old projects . This came with an array of problems. Like a lost database — which is being fixed.
NB: The following post will cover a lot with hasty information.
PHP is a big elephant in my brain room
Over the past odd number of alot of days , we have touched extensively on:
- Bit Manipulation
- printf
- File I/O
- password hashing (Fun thing I did)
printf
Simply put ,it is used to display output on your device. Copy, paste and run the following code snippets in this page to see. Example :
#include <stdio.h>int main() {
printf("Hello world");
return 0;
}
//Prints : Hello world
This however , only prints whatever is in our quoted brackets .What about when we want to print other data types?
Format specifiers come and camp here. Example:
#include <stdio.h>main() {
char ch = 'B';
printf("%c\n", ch); //printing character data //print decimal or integer data with d and i
int x = 45, y = 90;
printf("%d\n", x);
printf("%i\n", y); float f = 12.67;
printf("%f\n", f); //print float value
printf("%e\n", f); //print in scientific notation int a = 67;
printf("%o\n", a); //print in octal format
printf("%x\n", a); //print in hex format char str[] = "Hello World";
printf("%s\n", str);
}
These specifiy what type value you pass through and will want to be displayed.
More information here .
Bit Manipulation
This is applying logical operations( AND , OR , XOR , NOT ) on a sequence of bits or data shorter than a word ,to achieve a result.
There are a number of reasons to this mainly :
- error detection and correction algorithms
- data compression
- optimization
- encryption algorithms
- low -level device control
Bitwise Operations
Complexities were mentioned here also:
Time complexity O(n) — This is runtime depending on the n of digits.
- It measures the time taken to execute each statement of code in an algorithm.
- If a statement is set to execute repeatedly then the number of times that statement gets executed is equal to N multiplied by the time required to run that function each time.
- This goes deeper to something called Big O notation.
Space complexity O(n) — This is the total space taken by an algorithm with relation to it’s input size.
- Auxiliary space is the temporary or extra space used by the algorithm while it is being executed. Big O (O(n)) notation is widely used to indicate the space complexity of an algorithm.
- The space complexity will be proportional to the size of the input and so cannot be less than O(n) for an input of size n to cover for different data sizes
- For fixed-size inputs, the complexity will be a constant O(1).
More information can be found here .
File I/O — File input /output operations.
- A stream is a conduit of communication between a program and the outside world. It is used to transport data objects sequentially.
- An Input/Output (I/O) Stream represents a source of input or a destination of output.
- A stream can represent a wide range of diverse sources and destinations, such as disk files, devices, other applications, and memory arrays.
File Descriptors (FD , fildes)
- This is a unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket.
- Positive integer values are commonly used for file descriptors, with negative values reserved for “no value” or error circumstances.
- They are a part of POSIX ( a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems).
- It should have three standards:
- The file operations that can be performed on FD are:
open()
close()
read()
write()
append() among others .
*Note: Side article to be made to expound file operations, soon.
Password_hashing — done on a PHP Project
This came about in storing passwords in my since then non-existent table.
For security ,ofcourse , I mean who would store their passwords plainly just like that on a db? whoooo?
pfshhh — looks away
This is making “password1234” to “dfghjkpr034283t1y01wh9eindwp”.
Fun yeah?To me it is ,cause it worked lol.
So anyways on your command line terminal for php project:
1. open interactive shell
run php -a
This will open an interactive shell with >
denoted before you type your commands.
2.hashing
We will tell the system that we wanna scramble our password and store it in hash.> $hash = password_hash(“password1234”, PASSWORD_DEFAULT);
> echo hash;
- This will display our hashed password : dfghjkpr034283t1y01wh9eindwp
3.verification.
Ofcourse we need to tell our system that our scrambled words is infact our password so,> $match = password_verify(“password1234”, $hash);
> echo $match;
This will return 1 if true (match), 0 (do not match)
You can quit after and store your scrambled password on your db. This can be done severally, for different users and passwords.
***Follow the links and read more kindly.
Commit Count: 626