Saturday, June 22, 2019

Python Frozen Set Example

Python Frozen Set Example




# The frozenset() is an inbuilt function is
Python which takes an iterable object as
input and makes them immutable.
# Simply it freezes the iterable objects and
makes them unchangeable.

# Python program to understand frozenset()
function

# set declaration
number = {1, 2, 3, 4, 5, 6, 7, 8, 9}

print ("Object type of number is ",type(number))
# converting Sets to frozenset
fnumber = frozenset(number)
print ("object type of fnumber is ",type(fnumber))

# printing details
print("frozenset Object is : ", fnumber)

# Python program to understand use
# of frozenset function

# creating a dictionary
info = {"fname": "vijay", "age": 30, "sex": "Male",}

# making keys of dictionary as frozenset
key = frozenset(info)

# printing keys details
print('The frozen set is:', key)

# Python program to understand
# use of frozenset function

# below line will generate error
#TypeError: 'frozenset' object does not support
item assignment
fnumber[1] = "11"


OpenSSL: Generating an RSA Key From the Command Line

OpenSSL: Generating an

RSA Key From the

Command Line



 

Generate a 2048 bit RSA Key



openssl genrsa  -out private.pem 2048


Generate a 3072 bit RSA Key



openssl genrsa  -out private.pem 3072


Generate a 4096 bit RSA Key



openssl genrsa  -out private.pem 4096


prints out the various public or private key

components in plain text in addition to the

encoded version

openssl rsa -text -in private.pem



 

Export the RSA Public Key to a File



openssl rsa -in private.pem -outform PEM -pubout -out public.pem


   

The Generated Key Files

The generated files are base64-encoded encryption keys in plain text format.
If you select a password for your private key, its file will be encrypted with
your password. Be sure to remember this password or the key pair becomes
useless.

The private.pem file looks something like this:

-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEA6JtguftyimdvYIG4X7r6MmrPHBlhs9CrxPZ0nAb/a7bCDxav
/GSEKVQfE6JBI1Ehc7D8ylpI607hTXuBTqVA4Q/nWKPThdeknIl3ORhFlHfHjBhD
H60BwweOuV7mj0lT+gwdqUP/8HtcO6KkiKtXOZ7clZNPyD8kb/A5pq25ucMlcxhO
/aDteFmSudaftwp5CYFfLyX+BIel3mBqQ95DdQmZROrtgDQuspU4kCfMflbyPYso
JgB3uLV/RH7IWvUHwR+IAVjkjluBWdACOcOv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NKXfzay1rhDLIkCYF75+8iHnspxWUgqekUqDAvs1kI1A0MvNKo
QV1hAoGAGY4uqbcqVdrdCp/qe5NFWB+9gWVMq88TBppOXIPaM7MWOJR2mtH4e9Q4
sM1JLOfcCYjYeKVhED7woHmwtl4fy048+PHxGhPoN3ph7mmLd40w8dltFzT6DASe
QhKHiKlMXlmBfz2Et9oOdnQIBXiDUCHUtekEL4iiGguxdlhsI3Q=
-----END RSA PRIVATE KEY-----

 

The public key, public.pem, file looks like:



-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6JtguftyimdvYIG4X7r6
MmrPHBlhs9CrxPZ0nAb/a7bCDxav/GSEKVQfE6JBI1Ehc7D8ylpI607hTXuBTqVA
4Q/nWKPThdeknIl3ORhFlHfHjBhDH60BwweOuV7mj0lT+gwdqUP/8HtcO6KkiKtX
OZ7clZNPyD8kb/A5pq25ucMlcxhO/aDteFmSudaftwp5CYFfLyX+BIel3mBqQ95D
dQmZROrtgDQuspU4kCfMflbyPYsoJgB3uLV/RH7IWvUHwR+IAVjkjluBWdACOcOv
Etcss/gI7UIJ2RgcAfO7zICPIk7B4X49/dzmqDFjBMrm/DiSTbcBRoDHuEvtt59x
1wIDAQAB
-----END PUBLIC KEY-----


Encrypt/Decrypt Using RSA Public/Private Key

Step:-1
Create Demo.txt


cat demo.txt
Hello This is Demo for Encrypt file


Step:-2
Encrypt Demo.txt File using RSA Public Key
openssl rsautl -encrypt -in demo.txt -pubin -inkey public.pem -out demo_encrypted.pem


Step:-3
Decrypt Demo.txt Encrypted file using RSA Private Key
openssl rsautl -encrypt -in demo.txt -pubin -inkey public.pem -out demo_encrypted.pem


Step:4
Check the Decrypted file its should be same as demo.txt
cat demo_descrypted.pem
Hello This is Demo for Encrypt file

Thursday, June 20, 2019

Python Set Example-1

Python Set Example



# A set is an unordered collection of Unique elements.
seta=set('abcd')
print (seta)

l = ['apple','banana','orange','graps']
print ("object type is", type(l),)
b=set(l) # converted List into set objects
print ("Object Type is ", type(b),)

s = {'apple','banana','orange','graps'}
print ("object type is", type(s),)
c=set(s) # converted List into set objects
print ("Object Type is ", type(c),)


example=set('abcdefg')
print ("define variable",example)

example.add('z')
print ("define variable",example)

d=example.copy()
print("copy set example",d)

example.remove('a')
print("removed a element from example set",example)

list1 = [1, 2, 3]
list2 = [5, 6, 7]
set1 = set(list2)
set2 = set(list1)

# Update method
set1.update(set2)

# Print the updated set
print("set update example",set1)

example.discard ('c')
print ("discard c example",example)

example.clear()
print ("clear example",example)

Wireless Security Configuration: Protect Your Network Now!

Introduction: In today’s connected world, wireless networks are as common as smartphones, and they’re often the gateway to our personal, pr...