Friday, October 30, 2020

Operators - BITWISE operator in C - Language

 BITWISE operator
----------------

"BITWISE operator" is used to perform the operations on the "BITS".

What is the BITS?
"BITS" are 1 and 0's.

What is another name of "BITS"?
-> Another name of "BITS" is "binary language".
-> Another name of "BINARY LANGUAGE" is "MACHINE LANGUAGE".

The following are the "BITWISE OPERATORS" in C-Language
1) & - AND BITWISE OPETATOR
2) | - OR BITWISE OPERATOR
3) ^ - XOR BITWISE OPERATOR
       NOTE: XOR stands for "EXCLUSIVE OR"
4) >> - RIGHT SHIFT BITWISE OPERATOR
5) << - LEFT SHIFT BITWISE OPERATOR
6) ~ - ONE'S COMPLIMENT BITWISE OPERATOR


BITWISE OPERATORS
-----------------
1) & - AND BITWISE OPERATOR
-----------------------

& - AND BITWISE OPERATOR is used to perform "AND Logical operations on BITS".

What are the "AND logical operations on BITS"?

-> NOTE: True -1   False - 0

1 & 0 = 0
0 & 1 = 0
1 & 1 = 1
0 & 0 = 0

Lets say, I have one integer value: 10
10 -> what are the binary bits of 10?

decimal    Binary
10 = 1010
20 = 10100

WE collect reminder, lets calculate the bit value of 20.
Here, we divide 20 by 2 and we note the reminder.

2|20
2|10 = 0 reminder
2|5  = 0
2|2  = 1
  1  = 0

so, you put together from bottom, we have
10100


As we know,
1 byte = 8 bits
10 = 1010 -> 4 bits
20 = 10100 -> 5 bits

so, 10 = 0 0 0 0 1 0 1 0   -> we just add 4 0's for 10 to make 8 bits which is 1 byte
20 = 0 0 0 1 1 0 1 0 0 -> we have to add 3 0's

Now, lets apply AND bitwise operator

to make a bits, we are adding 0's. As we know one byte equal to 8 bits.

Now, lets apply AND bitwise operator

10 = 0 0 0 0 1 0 1 0
20 = 0 0 0 1 0 1 0 0
---------------------
     0 0 0 0 0 0 0 0

Now calculate,

2^0 -> 2 power 0 is equal to 0.
Here is an example why its 0.

0        0        0       0         0        0            0         0         
(2^7*0)  (2^6*0)   (2^5*0)   (2^4*0)   (2^3*0)  (2^2*0) +  (2^1*0)  +    (0^0*0) = 0 result

When we apply 'AND bitwise operator' on 10 and 20 numbers, then what is the result?
-> 0 is the result.

void main()

{
printf("%d", 10 & 20);
}

2) | - OR BITWISE OPERATOR
--------------------------

OR BITWISE OPERATOR is used to perform  OR logical operations on BITS.

What are the OR LOGICAL OPERATIONS on BITS?
->

1 | 0 = 1    True Or False -> True
0 | 1 = 1    True
1 | 1 = 1    True
0 | 0 = 0    False | False


Applying OR BITWISE Operator
10 = 0   0   0  0  1  0  1  0
20 = 0   0   0  1  0  1  0  0
-----------------------------
     0   0   0  1  1  1  1  0
now, calculate from roght to left

(2^7*0) (2^6*0) (2^5*0) (2^4*1) (2^3*1) (2^2*1) (2^1*1) (2^0*0)
---------------------------------------------------------------
   0   +  0    +  0    +   16 +    8 +     4 +     2   +  0 = 30 Result

So, if we apply 'OR bitwise operator on 10 and 20 numbers, what is the result?
The answer is 30.

void main()
{
  printf("%d", 10 | 20);
}


3) XOR BITWISE OPERATOR
========================

BITWISE OPERATORS are used for performing calculations on bits

Here, XOR stands for EXCLUSIVE OR

XOR operations on BITS:
------------------------
It is little bit different from OR BITWISE operator.

XOR - ^
1 ^ 0 = 1
0 ^ 1 = 1
0 ^ 0 = 0
1 ^ 1 = 0

Q. What is the difference between 'OR' and 'XOR' bitwise operator?
->
1 | 1 = 1
1 ^ 1 = 0


lets work on XOR bitwise operator.

Applying XOR BITWISE Operator
10 = 0   0   0  0  1  0  1  0
20 = 0   0   0  1  0  1  0  0
-----------------------------
     0   0   0  1  1  1  1  0

Since 1 on 10 and 1 on 20 do not fall on same order, that is why the result on 'OR' or 'XOR' comes same.


Result will be same: 30


Now, lets write the code

#include<stdio.h>
void main()
{
 clrscr();
 printf("%d", 10 ^ 20);
}


4) >> - RIGHTSHIFT BITWISE Operator
===================================
>> - two greater than signals.

Wednesday, October 21, 2020

RHEL7 - Creating LUKs encripted device on redhat

 Creating LUKs encripted device on RHEL7

1. Add device to your system either through VMware or SAN
# ls -l /dev/sdb

2. Partition your drive
# gdisk /dev/sdb

Type ? for help
Type n for new partition
change partition type to LVM
press w to write the partition.
press Y to confirm.
# fdisk -l

3. Now, its time to encript your device.
# cryptsetup --force-password --cipher aes-xts-plain64 luksFormat /dev/sdb1
Confirm by typing YES and it will prompt you for password. Keep/remember this password.

4. Now, open this device
# cryptsetup luksOpen /dev/sdb1 luks-$(cryptsetup luksUUID /dev/sdb1)
# cryptsetup luksUUID /dev/sdb1

5. Now, add device to crypttab
# uuid=$(cryptsetup luksUID /dev/sdb1); echo luks-$uuid UUID=$uuid none >> /etc/crypttab
# cat /etc/crypttab

6. Bring this device under LVM control
# pvcreate /dev/mapper/luks-$(cryptsetup luksUUID /dev/sdb1)
# pvs

7. Create volume group
# vgcreate vg1 /dev/mapper/luks-$(cryptsetup luksUUID /dev/sdb1)

---------------------------------------------------------
if you are extending
# vgextend vg1 /dev/mapper/luks-$(cryptsetup luksUUID /dev/sdb1)
# vgs
# lvs
# lvscan
# df -h /var
# lvextend -l +10G /dev/vg1/lv_var
# lvscan
# df -h /var
# xfs_growfs /dev/vg1/lv_var
# df -h /var # verify the change of the size.
---------------------------------------------------------
8. Create logical volume out off volume group
# lvcreate -L 10G -n lv_www vg1

9. Create filesystem
# lvscan
# mkfs.xfs /dev/mapper/vg1-lv_www

10. Add entry to fstab and mount the device.


Note: If you want to have a shorter password, look on pwquality.conf file to change the length of the pw.

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...