You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#Thanks to github.com/danielmiessler/SecLists/ for the datasetimportpandasaspdimportseabornassnsimportmatplotlib.pylabaspltimportnumpyasnpdf=pd.read_csv("four-digit-pin-codes-sorted-by-frequency-withcount.csv", header=None, dtype={0: 'string'})
#We formatted the first column as string to avoid the string "0000" to be simplified as "0"df.head()
0
1
0
1234
255
1
1111
244
2
0000
221
3
1212
212
4
7777
203
Our dataset is in the form "pin | occurrence"
df=df.sort_values(0) #Sort the dataset in numerical order so that we have all the number from 0 to 9999pesi_df= (df[1] -df[1].min()) / (df[1].max() -df[1].min()) #Let's map each "occurrence" to a number in the interval [0,1] (MinMax normalization)data_reshaped=pesi_df.values.reshape(100, 100) #Switch from a 1x10000 to a 100x100 array, where each index pair identifies the original 4-digit pindf_reshaped=pd.DataFrame(data_reshaped) #Turn it into a Pandas DataFrame for easier manipulationdf_reshaped=np.transpose(df_reshaped) #Somehow the reshape function inverts the orientation of the original matrix, so we need to transpose it along the principal diagonal
# Verifying the size of the new DataFrameprint(df_reshaped.shape) # Output: (100, 100)# Show some of the elements in the DataFrameprint(df_reshaped.head())
plt.figure(figsize=(60, 30)) #Create a new figure for the plotax=sns.heatmap(df_reshaped,square=True,linewidths=1,xticklabels=5, yticklabels=5) #The plot itself uses seaborn heatmap function. Changing the values here is purely for aesthetic reasonsplt.gca().invert_yaxis() #By default the y axis is represented in increasing order starting at the top. We want it to start at the bottom ax.set_yticklabels(ax.get_yticklabels(), fontsize=15) #Changing the font size of the x and y labelsax.set_xticklabels(ax.get_xticklabels(), fontsize=15)
ax.set_xlabel('First two digits',fontsize=60)
ax.set_ylabel('Last two digits',fontsize=60)
plt.savefig('foo1.png', bbox_inches='tight') #Save the graph...plt.show() #...and show it!
About
Pattern evaluation in 4 digit pin using pandas and seaborn