├── FastText_training.ipynb ├── LICENSE ├── No_w2kp_PRGraph.py ├── PasswordRetriever.py ├── README.md ├── images ├── 3dplot.png ├── US_keyboard_layout.png ├── big_model.png ├── cbow_vs_skipgram.png ├── logo.png ├── nngram_formula.png ├── no_w2kp_nmingram=2_epochs=5.png ├── precision_recall_formula.png ├── precisionrecall.png └── w2kp_nmingram=1_epochs=5.png ├── preparing_dataset.py ├── split_dataset.py ├── visualize_embeddings.py └── w2kp_PRGraph.py /FastText_training.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Password similarity measure using word embeddings with FastText" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "##### Author: _Karina Chichifoi_" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "## 0. Introduction" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "The purpose of this project is to see how similar are the passwords associated to a specific user. Word embeddings are useful for this task, because they can give some additional information about word contexts.\n", 29 | "\n", 30 | "In this notebook FastText is used as word embedding model. It represents each word as an _n-gram_ of characters. This method allows to understand the meaning of short words, and also of prefixes and suffixes, making the process of measuring the similarity of passwords easier." 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "## 1. Preconditions" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "Before training FastText, the following operation were performed on a 43 GB breach:\n", 45 | "- Removed passwords longer than 30 characters or shorter than 4.\n", 46 | "- Removed non ASCII printable characters in a password.\n", 47 | "- Removed bot, which are recognisable by the same mail used more than 100 times.\n", 48 | "- Removed HEX passwords (identified by `$HEX[]` and `\\x`).\n", 49 | "- Removed HTML char set.\n", 50 | "- Removed mail which appear more than 100 times and less than 2.\n", 51 | "- Removed mail with non-valid password.\n", 52 | "\n", 53 | "After that the passwords were converted in a key-press sequence, thanks to ```word2keypress``` python library. In this way is easier to see more similarities between two passwords.\n", 54 | "The results were saved in a csv file, which will be used as FastText dataset, in this way:\n", 55 | "\n", 56 | "```sample@gmail.com: [\"'97314348'\", \"'voyager1'\"]```\n", 57 | "\n" 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "metadata": {}, 63 | "source": [ 64 | "## 2 Environment setup" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": {}, 70 | "source": [ 71 | "First of all import all useful libraries." 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 1, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "from gensim.models import FastText\n", 81 | "import time\n", 82 | "import sys\n", 83 | "from pathlib import Path\n", 84 | "from PasswordRetriever import PasswordRetriever" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": {}, 90 | "source": [ 91 | "```PasswordRetriever``` is a helper class which retrieves a list of passwords from the cleaned csv file." 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "## 3. Train FastText model" 99 | ] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "metadata": {}, 104 | "source": [ 105 | "### 3.1 FastText parameters" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "Choose the parameters for FastText embedding model." 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 2, 118 | "metadata": {}, 119 | "outputs": [], 120 | "source": [ 121 | "negative = 5\n", 122 | "subsampling = 1e-3\n", 123 | "min_count = 10\n", 124 | "min_n = 1 \n", 125 | "max_n = 4 \n", 126 | "SIZE = 200 # dimension of the model\n", 127 | "sg = 1" 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "metadata": {}, 133 | "source": [ 134 | "In this case it was used the _skip-gram approach_ (`sg = 1`) with _negative sampling_.\n", 135 | "\n", 136 | "- _Skip-gram model_ is chosen, as the distributed representation of the input word is used to predict the context.\n", 137 | "_Skip-gram model_ works better with subword information, so it is recommended for learning passwords and rare words in general.\n", 138 | "\n", 139 | "- _Negative sampling_ makes the training faster. Each training sample updates only a small percentage of the model's weights. For larger datasets (like this case) it is recommended to set _negative sampling_ between 2 and 5.\n", 140 | "\n", 141 | "- The dimension of vectors is set to ```200```, in order to have train the model faster. Generally it is recommended to have `SIZE = 300`. \n", 142 | "\n", 143 | "- The ```subsampling``` ignores the most frequent password (more than 1000 occurrences).\n", 144 | "\n", 145 | "- ```min_count``` represents the minimum number of occurences of a password in the training dataset.\n", 146 | "\n", 147 | "- ```min_n``` and ```max_n``` are the number of respectively _minimum_ and _maximum n-grams_.\n", 148 | " - _N-grams_ are used in statistical natural language processing to predict a word and/or the context of a word. \n", 149 | " In this case they represent a contiguous sequence of n characters and their purpose is to give subword information.\n", 150 | "\n", 151 | " For example a password `w = qwerty` with `min_n = 4` and `m_max = 5`, will have the following n-grams.\n", 152 | " `zw = {, }`\n", 153 | "\n", 154 | " NB `<` and `>` are considered as characters." 155 | ] 156 | }, 157 | { 158 | "cell_type": "markdown", 159 | "metadata": {}, 160 | "source": [ 161 | "### 3.2 Training FastText" 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": {}, 167 | "source": [ 168 | "The list of password related to every user is obtained from the helper class `PasswordRetriever`.\n", 169 | "FastText is ready to train the model, based on `password_list`." 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 3, 175 | "metadata": {}, 176 | "outputs": [ 177 | { 178 | "name": "stdout", 179 | "output_type": "stream", 180 | "text": [ 181 | "Processed 0 lines in 3.981590270996094e-05 seconds.\n", 182 | "Processed 1000000 lines in 8.32761836051941 seconds.\n", 183 | "Processed 2000000 lines in 8.211445093154907 seconds.\n", 184 | "Processed 3000000 lines in 8.039046287536621 seconds.\n", 185 | "Processed 4000000 lines in 8.645042657852173 seconds.\n", 186 | "Processed 5000000 lines in 8.688397884368896 seconds.\n", 187 | "Processed 6000000 lines in 8.762989521026611 seconds.\n", 188 | "Processed 7000000 lines in 9.28832745552063 seconds.\n", 189 | "Processed 8000000 lines in 9.370487928390503 seconds.\n", 190 | "Processed 9000000 lines in 8.766379356384277 seconds.\n", 191 | "Processed 10000000 lines in 8.871519088745117 seconds.\n", 192 | "Processed 11000000 lines in 8.899347305297852 seconds.\n", 193 | "Processed 12000000 lines in 8.987047910690308 seconds.\n", 194 | "Processed 13000000 lines in 9.068806409835815 seconds.\n", 195 | "Processed 14000000 lines in 9.055849313735962 seconds.\n", 196 | "Processed 15000000 lines in 10.101937294006348 seconds.\n", 197 | "Processed 16000000 lines in 9.06157922744751 seconds.\n", 198 | "Processed 17000000 lines in 9.10492467880249 seconds.\n", 199 | "Processed 18000000 lines in 10.152393817901611 seconds.\n", 200 | "Processed 19000000 lines in 9.125312089920044 seconds.\n", 201 | "Processed 20000000 lines in 9.097816228866577 seconds.\n", 202 | "Processed 21000000 lines in 9.12251877784729 seconds.\n", 203 | "Processed 22000000 lines in 9.093791246414185 seconds.\n", 204 | "Processed 23000000 lines in 9.09725308418274 seconds.\n", 205 | "Processed 24000000 lines in 9.079681396484375 seconds.\n", 206 | "Processed 25000000 lines in 9.053807497024536 seconds.\n", 207 | "Processed 26000000 lines in 9.03109622001648 seconds.\n", 208 | "Processed 27000000 lines in 8.978954076766968 seconds.\n", 209 | "Processed 28000000 lines in 9.01730990409851 seconds.\n", 210 | "Processed 29000000 lines in 8.99671220779419 seconds.\n", 211 | "Processed 30000000 lines in 9.134580612182617 seconds.\n", 212 | "Processed 31000000 lines in 9.142038345336914 seconds.\n", 213 | "Processed 32000000 lines in 11.395709753036499 seconds.\n", 214 | "Processed 33000000 lines in 9.098125457763672 seconds.\n", 215 | "Processed 34000000 lines in 9.047677993774414 seconds.\n", 216 | "Processed 35000000 lines in 9.141824960708618 seconds.\n", 217 | "Processed 36000000 lines in 9.070488452911377 seconds.\n", 218 | "Processed 37000000 lines in 9.11714506149292 seconds.\n", 219 | "Processed 38000000 lines in 9.115279197692871 seconds.\n", 220 | "Processed 39000000 lines in 9.222779273986816 seconds.\n", 221 | "Processed 40000000 lines in 12.469627141952515 seconds.\n", 222 | "Processed 41000000 lines in 9.035439014434814 seconds.\n", 223 | "Processed 42000000 lines in 9.068572759628296 seconds.\n", 224 | "Processed 43000000 lines in 9.12914228439331 seconds.\n", 225 | "Processed 44000000 lines in 8.993815898895264 seconds.\n", 226 | "Processed 45000000 lines in 9.00800609588623 seconds.\n", 227 | "Processed 46000000 lines in 9.024227380752563 seconds.\n", 228 | "Processed 47000000 lines in 9.021472454071045 seconds.\n", 229 | "Processed 48000000 lines in 8.967662572860718 seconds.\n", 230 | "Processed 49000000 lines in 8.985406875610352 seconds.\n", 231 | "Processed 50000000 lines in 9.039650440216064 seconds.\n", 232 | "Processed 51000000 lines in 9.08467411994934 seconds.\n", 233 | "Processed 52000000 lines in 9.0839102268219 seconds.\n", 234 | "Processed 53000000 lines in 9.127612113952637 seconds.\n", 235 | "Processed 54000000 lines in 9.102632284164429 seconds.\n", 236 | "Processed 55000000 lines in 9.06694221496582 seconds.\n", 237 | "Processed 56000000 lines in 9.07617974281311 seconds.\n", 238 | "Processed 57000000 lines in 9.10299038887024 seconds.\n", 239 | "Processed 58000000 lines in 9.046988010406494 seconds.\n", 240 | "Processed 59000000 lines in 9.157943725585938 seconds.\n", 241 | "Processed 60000000 lines in 9.198299646377563 seconds.\n", 242 | "Processed 61000000 lines in 8.971093654632568 seconds.\n", 243 | "Processed 62000000 lines in 9.030171632766724 seconds.\n", 244 | "Processed 63000000 lines in 9.123520374298096 seconds.\n", 245 | "Processed 64000000 lines in 9.061663389205933 seconds.\n", 246 | "Processed 65000000 lines in 9.217504262924194 seconds.\n", 247 | "Processed 66000000 lines in 9.282256841659546 seconds.\n", 248 | "Processed 67000000 lines in 9.325484037399292 seconds.\n", 249 | "Processed 68000000 lines in 9.308762073516846 seconds.\n", 250 | "Processed 69000000 lines in 9.153597593307495 seconds.\n", 251 | "Processed 70000000 lines in 59.942655086517334 seconds.\n", 252 | "Processed 71000000 lines in 15.626888036727905 seconds.\n", 253 | "Processed 72000000 lines in 15.284328937530518 seconds.\n", 254 | "Processed 73000000 lines in 14.423210859298706 seconds.\n", 255 | "Processed 74000000 lines in 14.071412563323975 seconds.\n", 256 | "Processed 75000000 lines in 13.326776504516602 seconds.\n", 257 | "Processed 76000000 lines in 17.802956581115723 seconds.\n", 258 | "Processed 77000000 lines in 23.796905994415283 seconds.\n", 259 | "Processed 78000000 lines in 15.765059232711792 seconds.\n", 260 | "Processed 79000000 lines in 12.600426435470581 seconds.\n", 261 | "Processed 80000000 lines in 11.476953744888306 seconds.\n", 262 | "Processed 81000000 lines in 10.931641578674316 seconds.\n", 263 | "Processed 82000000 lines in 10.81622838973999 seconds.\n", 264 | "Processed 83000000 lines in 10.5299973487854 seconds.\n", 265 | "Processed 84000000 lines in 11.22444486618042 seconds.\n", 266 | "Processed 85000000 lines in 12.531036138534546 seconds.\n", 267 | "Processed 86000000 lines in 12.122101783752441 seconds.\n", 268 | "Processed 87000000 lines in 12.492013692855835 seconds.\n", 269 | "Processed 88000000 lines in 89.16427731513977 seconds.\n", 270 | "Processed 89000000 lines in 36.113338232040405 seconds.\n", 271 | "Processed 90000000 lines in 26.342081308364868 seconds.\n", 272 | "Processed 91000000 lines in 35.848020792007446 seconds.\n", 273 | "Processed 92000000 lines in 27.278318405151367 seconds.\n", 274 | "Processed 93000000 lines in 19.207103729248047 seconds.\n", 275 | "Processed 94000000 lines in 16.861185312271118 seconds.\n", 276 | "Processed 95000000 lines in 19.221708059310913 seconds.\n", 277 | "Processed 96000000 lines in 20.081425428390503 seconds.\n", 278 | "Processed 97000000 lines in 19.948221921920776 seconds.\n", 279 | "Processed 98000000 lines in 28.352442741394043 seconds.\n", 280 | "Processed 99000000 lines in 26.517688751220703 seconds.\n", 281 | "Processed 100000000 lines in 26.641544103622437 seconds.\n", 282 | "Processed 101000000 lines in 33.65659737586975 seconds.\n", 283 | "Processed 102000000 lines in 36.85259246826172 seconds.\n", 284 | "Processed 103000000 lines in 32.91370439529419 seconds.\n", 285 | "Processed 104000000 lines in 36.43045735359192 seconds.\n", 286 | "Processed 105000000 lines in 32.94820046424866 seconds.\n", 287 | "Processed 106000000 lines in 35.32076954841614 seconds.\n", 288 | "Processed 107000000 lines in 41.591822147369385 seconds.\n", 289 | "Processed 108000000 lines in 38.25136351585388 seconds.\n", 290 | "Processed 109000000 lines in 40.081403493881226 seconds.\n", 291 | "Processed 110000000 lines in 40.88752841949463 seconds.\n", 292 | "Processed 111000000 lines in 45.31127166748047 seconds.\n", 293 | "Processed 112000000 lines in 51.101927518844604 seconds.\n", 294 | "Processed 113000000 lines in 43.772372245788574 seconds.\n", 295 | "Processed 114000000 lines in 47.324684619903564 seconds.\n", 296 | "Processed 115000000 lines in 50.812888383865356 seconds.\n", 297 | "Processed 116000000 lines in 57.414888858795166 seconds.\n", 298 | "Processed 117000000 lines in 56.47319793701172 seconds.\n", 299 | "Processed 118000000 lines in 54.114577770233154 seconds.\n", 300 | "Processed 119000000 lines in 56.30802869796753 seconds.\n", 301 | "Processed 120000000 lines in 63.7755823135376 seconds.\n", 302 | "Processed 121000000 lines in 58.16217637062073 seconds.\n", 303 | "Processed 122000000 lines in 61.00149893760681 seconds.\n", 304 | "Processed 123000000 lines in 69.86021065711975 seconds.\n", 305 | "Processed 124000000 lines in 64.04530143737793 seconds.\n", 306 | "Processed 125000000 lines in 64.36019206047058 seconds.\n", 307 | "Processed 126000000 lines in 71.97378921508789 seconds.\n", 308 | "Processed 127000000 lines in 67.79710555076599 seconds.\n", 309 | "Processed 128000000 lines in 73.25906944274902 seconds.\n", 310 | "Processed 0 lines in 0.0012106895446777344 seconds.\n", 311 | "Processed 1000000 lines in 68.84693598747253 seconds.\n", 312 | "Processed 2000000 lines in 11.168041467666626 seconds.\n", 313 | "Processed 3000000 lines in 10.97093653678894 seconds.\n", 314 | "Processed 4000000 lines in 10.846105098724365 seconds.\n", 315 | "Processed 5000000 lines in 13.275620698928833 seconds.\n", 316 | "Processed 6000000 lines in 13.063545227050781 seconds.\n", 317 | "Processed 7000000 lines in 12.564296960830688 seconds.\n", 318 | "Processed 8000000 lines in 12.878262281417847 seconds.\n", 319 | "Processed 9000000 lines in 12.729820966720581 seconds.\n", 320 | "Processed 10000000 lines in 12.885352373123169 seconds.\n", 321 | "Processed 11000000 lines in 12.729207515716553 seconds.\n", 322 | "Processed 12000000 lines in 12.521856546401978 seconds.\n", 323 | "Processed 13000000 lines in 12.789563417434692 seconds.\n", 324 | "Processed 14000000 lines in 12.83245849609375 seconds.\n", 325 | "Processed 15000000 lines in 12.590209722518921 seconds.\n", 326 | "Processed 16000000 lines in 12.782467126846313 seconds.\n", 327 | "Processed 17000000 lines in 13.394484281539917 seconds.\n", 328 | "Processed 18000000 lines in 12.518709897994995 seconds.\n", 329 | "Processed 19000000 lines in 13.153722047805786 seconds.\n", 330 | "Processed 20000000 lines in 12.642543315887451 seconds.\n", 331 | "Processed 21000000 lines in 12.824453830718994 seconds.\n", 332 | "Processed 22000000 lines in 12.80319595336914 seconds.\n", 333 | "Processed 23000000 lines in 12.429438829421997 seconds.\n", 334 | "Processed 24000000 lines in 12.715332746505737 seconds.\n", 335 | "Processed 25000000 lines in 12.624751329421997 seconds.\n", 336 | "Processed 26000000 lines in 12.150895357131958 seconds.\n", 337 | "Processed 27000000 lines in 12.52712607383728 seconds.\n", 338 | "Processed 28000000 lines in 12.489778518676758 seconds.\n", 339 | "Processed 29000000 lines in 12.003856420516968 seconds.\n", 340 | "Processed 30000000 lines in 12.621047019958496 seconds.\n", 341 | "Processed 31000000 lines in 12.22782015800476 seconds.\n", 342 | "Processed 32000000 lines in 12.595577955245972 seconds.\n", 343 | "Processed 33000000 lines in 12.373632669448853 seconds.\n", 344 | "Processed 34000000 lines in 12.230362892150879 seconds.\n", 345 | "Processed 35000000 lines in 12.997738122940063 seconds.\n", 346 | "Processed 36000000 lines in 12.191466093063354 seconds.\n", 347 | "Processed 37000000 lines in 11.980647087097168 seconds.\n", 348 | "Processed 38000000 lines in 12.391333818435669 seconds.\n", 349 | "Processed 39000000 lines in 12.349311828613281 seconds.\n", 350 | "Processed 40000000 lines in 11.808176040649414 seconds.\n", 351 | "Processed 41000000 lines in 12.29535460472107 seconds.\n", 352 | "Processed 42000000 lines in 12.19413948059082 seconds.\n", 353 | "Processed 43000000 lines in 12.704156160354614 seconds.\n", 354 | "Processed 44000000 lines in 12.557606220245361 seconds.\n", 355 | "Processed 45000000 lines in 12.371106147766113 seconds.\n", 356 | "Processed 46000000 lines in 34.98995327949524 seconds.\n", 357 | "Processed 47000000 lines in 11.995881795883179 seconds.\n", 358 | "Processed 48000000 lines in 11.431119203567505 seconds.\n", 359 | "Processed 49000000 lines in 12.025180339813232 seconds.\n", 360 | "Processed 50000000 lines in 12.048519134521484 seconds.\n", 361 | "Processed 51000000 lines in 12.041435241699219 seconds.\n", 362 | "Processed 52000000 lines in 11.79090666770935 seconds.\n", 363 | "Processed 53000000 lines in 11.537108659744263 seconds.\n", 364 | "Processed 54000000 lines in 12.094674348831177 seconds.\n", 365 | "Processed 55000000 lines in 12.104140996932983 seconds.\n", 366 | "Processed 56000000 lines in 11.597570896148682 seconds.\n", 367 | "Processed 57000000 lines in 12.383633136749268 seconds.\n", 368 | "Processed 58000000 lines in 11.721169233322144 seconds.\n", 369 | "Processed 59000000 lines in 11.667007684707642 seconds.\n", 370 | "Processed 60000000 lines in 12.244426727294922 seconds.\n", 371 | "Processed 61000000 lines in 11.695767402648926 seconds.\n", 372 | "Processed 62000000 lines in 11.891989946365356 seconds.\n", 373 | "Processed 63000000 lines in 12.039416790008545 seconds.\n", 374 | "Processed 64000000 lines in 11.809604167938232 seconds.\n", 375 | "Processed 65000000 lines in 12.06983470916748 seconds.\n", 376 | "Processed 66000000 lines in 12.020373344421387 seconds.\n", 377 | "Processed 67000000 lines in 11.88576602935791 seconds.\n", 378 | "Processed 68000000 lines in 11.930294275283813 seconds.\n", 379 | "Processed 69000000 lines in 12.053581476211548 seconds.\n", 380 | "Processed 70000000 lines in 11.619017362594604 seconds.\n", 381 | "Processed 71000000 lines in 11.87468957901001 seconds.\n", 382 | "Processed 72000000 lines in 11.641377925872803 seconds.\n", 383 | "Processed 73000000 lines in 12.135434865951538 seconds.\n", 384 | "Processed 74000000 lines in 11.893250226974487 seconds.\n", 385 | "Processed 75000000 lines in 11.928030490875244 seconds.\n", 386 | "Processed 76000000 lines in 11.72824478149414 seconds.\n", 387 | "Processed 77000000 lines in 12.0641348361969 seconds.\n", 388 | "Processed 78000000 lines in 11.683890104293823 seconds.\n", 389 | "Processed 79000000 lines in 12.238908052444458 seconds.\n", 390 | "Processed 80000000 lines in 12.004598379135132 seconds.\n", 391 | "Processed 81000000 lines in 11.597167730331421 seconds.\n", 392 | "Processed 82000000 lines in 12.103559732437134 seconds.\n", 393 | "Processed 83000000 lines in 11.682849884033203 seconds.\n", 394 | "Processed 84000000 lines in 11.768422365188599 seconds.\n", 395 | "Processed 85000000 lines in 11.707257747650146 seconds.\n", 396 | "Processed 86000000 lines in 11.560875177383423 seconds.\n", 397 | "Processed 87000000 lines in 11.979645013809204 seconds.\n", 398 | "Processed 88000000 lines in 11.808533191680908 seconds.\n", 399 | "Processed 89000000 lines in 11.901595830917358 seconds.\n", 400 | "Processed 90000000 lines in 11.892274379730225 seconds.\n", 401 | "Processed 91000000 lines in 11.577476501464844 seconds.\n", 402 | "Processed 92000000 lines in 11.936104536056519 seconds.\n", 403 | "Processed 93000000 lines in 11.740949153900146 seconds.\n", 404 | "Processed 94000000 lines in 11.646675825119019 seconds.\n", 405 | "Processed 95000000 lines in 12.04584813117981 seconds.\n", 406 | "Processed 96000000 lines in 11.902093887329102 seconds.\n", 407 | "Processed 97000000 lines in 11.558668613433838 seconds.\n", 408 | "Processed 98000000 lines in 11.930173635482788 seconds.\n", 409 | "Processed 99000000 lines in 11.937313556671143 seconds.\n", 410 | "Processed 100000000 lines in 11.994746685028076 seconds.\n", 411 | "Processed 101000000 lines in 11.902766704559326 seconds.\n", 412 | "Processed 102000000 lines in 11.835922718048096 seconds.\n", 413 | "Processed 103000000 lines in 11.768280267715454 seconds.\n", 414 | "Processed 104000000 lines in 11.986276626586914 seconds.\n", 415 | "Processed 105000000 lines in 11.935389518737793 seconds.\n", 416 | "Processed 106000000 lines in 12.108407258987427 seconds.\n", 417 | "Processed 107000000 lines in 12.262128353118896 seconds.\n", 418 | "Processed 108000000 lines in 11.661928176879883 seconds.\n", 419 | "Processed 109000000 lines in 12.113945722579956 seconds.\n", 420 | "Processed 110000000 lines in 11.903327703475952 seconds.\n", 421 | "Processed 111000000 lines in 11.74354100227356 seconds.\n", 422 | "Processed 112000000 lines in 12.09400725364685 seconds.\n", 423 | "Processed 113000000 lines in 11.51280426979065 seconds.\n", 424 | "Processed 114000000 lines in 11.813150882720947 seconds.\n", 425 | "Processed 115000000 lines in 12.034647226333618 seconds.\n", 426 | "Processed 116000000 lines in 11.698277235031128 seconds.\n", 427 | "Processed 117000000 lines in 11.899101495742798 seconds.\n", 428 | "Processed 118000000 lines in 12.215120077133179 seconds.\n", 429 | "Processed 119000000 lines in 11.730506896972656 seconds.\n", 430 | "Processed 120000000 lines in 11.928377389907837 seconds.\n", 431 | "Processed 121000000 lines in 12.15605902671814 seconds.\n", 432 | "Processed 122000000 lines in 11.713261842727661 seconds.\n", 433 | "Processed 123000000 lines in 11.789839744567871 seconds.\n", 434 | "Processed 124000000 lines in 11.949562549591064 seconds.\n", 435 | "Processed 125000000 lines in 11.529197454452515 seconds.\n", 436 | "Processed 126000000 lines in 11.487278699874878 seconds.\n", 437 | "Processed 127000000 lines in 11.353040933609009 seconds.\n", 438 | "Processed 128000000 lines in 11.493170976638794 seconds.\n", 439 | "Processed 0 lines in 0.0002105236053466797 seconds.\n", 440 | "Processed 1000000 lines in 10.724919080734253 seconds.\n", 441 | "Processed 2000000 lines in 9.67183780670166 seconds.\n", 442 | "Processed 3000000 lines in 10.108468055725098 seconds.\n", 443 | "Processed 4000000 lines in 10.212220430374146 seconds.\n", 444 | "Processed 5000000 lines in 12.080944538116455 seconds.\n", 445 | "Processed 6000000 lines in 11.50892424583435 seconds.\n", 446 | "Processed 7000000 lines in 11.744571924209595 seconds.\n", 447 | "Processed 8000000 lines in 11.612807512283325 seconds.\n", 448 | "Processed 9000000 lines in 11.911502838134766 seconds.\n", 449 | "Processed 10000000 lines in 11.78684687614441 seconds.\n", 450 | "Processed 11000000 lines in 11.652033567428589 seconds.\n", 451 | "Processed 12000000 lines in 11.784423589706421 seconds.\n", 452 | "Processed 13000000 lines in 11.707046270370483 seconds.\n", 453 | "Processed 14000000 lines in 12.23026418685913 seconds.\n", 454 | "Processed 15000000 lines in 12.089486360549927 seconds.\n", 455 | "Processed 16000000 lines in 12.041897296905518 seconds.\n", 456 | "Processed 17000000 lines in 12.540453910827637 seconds.\n", 457 | "Processed 18000000 lines in 12.426127672195435 seconds.\n", 458 | "Processed 19000000 lines in 12.230402946472168 seconds.\n", 459 | "Processed 20000000 lines in 12.567630052566528 seconds.\n", 460 | "Processed 21000000 lines in 12.378057479858398 seconds.\n", 461 | "Processed 22000000 lines in 12.146494626998901 seconds.\n", 462 | "Processed 23000000 lines in 12.354315042495728 seconds.\n", 463 | "Processed 24000000 lines in 11.994749784469604 seconds.\n", 464 | "Processed 25000000 lines in 11.93916392326355 seconds.\n", 465 | "Processed 26000000 lines in 12.060572862625122 seconds.\n", 466 | "Processed 27000000 lines in 11.688495635986328 seconds.\n", 467 | "Processed 28000000 lines in 12.131058931350708 seconds.\n", 468 | "Processed 29000000 lines in 11.855942487716675 seconds.\n", 469 | "Processed 30000000 lines in 11.799220561981201 seconds.\n", 470 | "Processed 31000000 lines in 12.24069881439209 seconds.\n", 471 | "Processed 32000000 lines in 12.272900104522705 seconds.\n", 472 | "Processed 33000000 lines in 11.850889921188354 seconds.\n", 473 | "Processed 34000000 lines in 11.987865447998047 seconds.\n", 474 | "Processed 35000000 lines in 12.581097602844238 seconds.\n", 475 | "Processed 36000000 lines in 11.823526620864868 seconds.\n", 476 | "Processed 37000000 lines in 12.001393556594849 seconds.\n", 477 | "Processed 38000000 lines in 11.556404113769531 seconds.\n", 478 | "Processed 39000000 lines in 12.053769588470459 seconds.\n", 479 | "Processed 40000000 lines in 12.110000610351562 seconds.\n", 480 | "Processed 41000000 lines in 11.579465389251709 seconds.\n", 481 | "Processed 42000000 lines in 12.11417818069458 seconds.\n", 482 | "Processed 43000000 lines in 12.2826988697052 seconds.\n", 483 | "Processed 44000000 lines in 11.893769264221191 seconds.\n", 484 | "Processed 45000000 lines in 12.082493305206299 seconds.\n", 485 | "Processed 46000000 lines in 11.771172285079956 seconds.\n", 486 | "Processed 47000000 lines in 12.247114896774292 seconds.\n", 487 | "Processed 48000000 lines in 11.835518598556519 seconds.\n", 488 | "Processed 49000000 lines in 11.670758962631226 seconds.\n", 489 | "Processed 50000000 lines in 12.360666751861572 seconds.\n", 490 | "Processed 51000000 lines in 12.108993768692017 seconds.\n", 491 | "Processed 52000000 lines in 11.669157981872559 seconds.\n", 492 | "Processed 53000000 lines in 12.025634527206421 seconds.\n", 493 | "Processed 54000000 lines in 11.852323532104492 seconds.\n", 494 | "Processed 55000000 lines in 11.620748519897461 seconds.\n", 495 | "Processed 56000000 lines in 11.940655708312988 seconds.\n", 496 | "Processed 57000000 lines in 11.87061071395874 seconds.\n", 497 | "Processed 58000000 lines in 11.914406299591064 seconds.\n", 498 | "Processed 59000000 lines in 11.905610084533691 seconds.\n", 499 | "Processed 60000000 lines in 11.92343282699585 seconds.\n", 500 | "Processed 61000000 lines in 12.119637966156006 seconds.\n", 501 | "Processed 62000000 lines in 11.82524037361145 seconds.\n", 502 | "Processed 63000000 lines in 11.752005338668823 seconds.\n", 503 | "Processed 64000000 lines in 12.127564668655396 seconds.\n", 504 | "Processed 65000000 lines in 11.99790072441101 seconds.\n", 505 | "Processed 66000000 lines in 11.839207887649536 seconds.\n", 506 | "Processed 67000000 lines in 12.03927993774414 seconds.\n", 507 | "Processed 68000000 lines in 11.575611114501953 seconds.\n", 508 | "Processed 69000000 lines in 12.175341367721558 seconds.\n", 509 | "Processed 70000000 lines in 11.906296253204346 seconds.\n", 510 | "Processed 71000000 lines in 11.557367086410522 seconds.\n", 511 | "Processed 72000000 lines in 11.848133087158203 seconds.\n", 512 | "Processed 73000000 lines in 12.00445294380188 seconds.\n", 513 | "Processed 74000000 lines in 11.624146223068237 seconds.\n", 514 | "Processed 75000000 lines in 12.15938949584961 seconds.\n", 515 | "Processed 76000000 lines in 11.794418573379517 seconds.\n", 516 | "Processed 77000000 lines in 11.354492664337158 seconds.\n", 517 | "Processed 78000000 lines in 12.09618330001831 seconds.\n", 518 | "Processed 79000000 lines in 11.68315076828003 seconds.\n", 519 | "Processed 80000000 lines in 12.117294073104858 seconds.\n", 520 | "Processed 81000000 lines in 12.087356805801392 seconds.\n", 521 | "Processed 82000000 lines in 11.577133178710938 seconds.\n", 522 | "Processed 83000000 lines in 11.845413446426392 seconds.\n", 523 | "Processed 84000000 lines in 12.003115177154541 seconds.\n", 524 | "Processed 85000000 lines in 11.433077573776245 seconds.\n", 525 | "Processed 86000000 lines in 12.0409677028656 seconds.\n", 526 | "Processed 87000000 lines in 11.689669609069824 seconds.\n", 527 | "Processed 88000000 lines in 11.710347175598145 seconds.\n", 528 | "Processed 89000000 lines in 12.151530265808105 seconds.\n", 529 | "Processed 90000000 lines in 11.451151847839355 seconds.\n", 530 | "Processed 91000000 lines in 11.936026573181152 seconds.\n", 531 | "Processed 92000000 lines in 12.07900595664978 seconds.\n", 532 | "Processed 93000000 lines in 11.496222019195557 seconds.\n", 533 | "Processed 94000000 lines in 11.88033413887024 seconds.\n", 534 | "Processed 95000000 lines in 11.842597246170044 seconds.\n", 535 | "Processed 96000000 lines in 11.585114479064941 seconds.\n", 536 | "Processed 97000000 lines in 11.778516292572021 seconds.\n", 537 | "Processed 98000000 lines in 11.988902807235718 seconds.\n", 538 | "Processed 99000000 lines in 11.826102018356323 seconds.\n", 539 | "Processed 100000000 lines in 11.969173908233643 seconds.\n", 540 | "Processed 101000000 lines in 11.869528532028198 seconds.\n", 541 | "Processed 102000000 lines in 12.113907098770142 seconds.\n", 542 | "Processed 103000000 lines in 11.890297412872314 seconds.\n", 543 | "Processed 104000000 lines in 11.837042093276978 seconds.\n", 544 | "Processed 105000000 lines in 11.963999032974243 seconds.\n", 545 | "Processed 106000000 lines in 12.058017492294312 seconds.\n", 546 | "Processed 107000000 lines in 11.867327213287354 seconds.\n", 547 | "Processed 108000000 lines in 12.0079026222229 seconds.\n", 548 | "Processed 109000000 lines in 11.621639251708984 seconds.\n", 549 | "Processed 110000000 lines in 12.003088235855103 seconds.\n", 550 | "Processed 111000000 lines in 11.882352828979492 seconds.\n", 551 | "Processed 112000000 lines in 11.59533429145813 seconds.\n", 552 | "Processed 113000000 lines in 11.837088346481323 seconds.\n", 553 | "Processed 114000000 lines in 11.868823766708374 seconds.\n", 554 | "Processed 115000000 lines in 11.716094970703125 seconds.\n", 555 | "Processed 116000000 lines in 12.077614068984985 seconds.\n", 556 | "Processed 117000000 lines in 11.940791130065918 seconds.\n", 557 | "Processed 118000000 lines in 11.683695793151855 seconds.\n", 558 | "Processed 119000000 lines in 12.127585411071777 seconds.\n", 559 | "Processed 120000000 lines in 11.722809553146362 seconds.\n", 560 | "Processed 121000000 lines in 12.12535810470581 seconds.\n", 561 | "Processed 122000000 lines in 11.733335256576538 seconds.\n", 562 | "Processed 123000000 lines in 11.568918228149414 seconds.\n", 563 | "Processed 124000000 lines in 12.226501703262329 seconds.\n", 564 | "Processed 125000000 lines in 11.40297794342041 seconds.\n", 565 | "Processed 126000000 lines in 11.194119215011597 seconds.\n", 566 | "Processed 127000000 lines in 11.655784130096436 seconds.\n", 567 | "Processed 128000000 lines in 11.585093021392822 seconds.\n", 568 | "Processed 0 lines in 0.0001685619354248047 seconds.\n", 569 | "Processed 1000000 lines in 10.284428358078003 seconds.\n", 570 | "Processed 2000000 lines in 10.039156913757324 seconds.\n", 571 | "Processed 3000000 lines in 10.286544561386108 seconds.\n", 572 | "Processed 4000000 lines in 9.930092573165894 seconds.\n", 573 | "Processed 5000000 lines in 12.474860191345215 seconds.\n", 574 | "Processed 6000000 lines in 11.3857421875 seconds.\n", 575 | "Processed 7000000 lines in 11.675435781478882 seconds.\n", 576 | "Processed 8000000 lines in 11.88646125793457 seconds.\n", 577 | "Processed 9000000 lines in 11.549269437789917 seconds.\n", 578 | "Processed 10000000 lines in 12.0137197971344 seconds.\n", 579 | "Processed 11000000 lines in 12.12113094329834 seconds.\n", 580 | "Processed 12000000 lines in 12.027921676635742 seconds.\n", 581 | "Processed 13000000 lines in 12.263740301132202 seconds.\n", 582 | "Processed 14000000 lines in 12.240964651107788 seconds.\n", 583 | "Processed 15000000 lines in 12.216225147247314 seconds.\n", 584 | "Processed 16000000 lines in 12.209858655929565 seconds.\n", 585 | "Processed 17000000 lines in 12.733371496200562 seconds.\n", 586 | "Processed 18000000 lines in 12.959535598754883 seconds.\n", 587 | "Processed 19000000 lines in 12.204669713973999 seconds.\n", 588 | "Processed 20000000 lines in 12.594193458557129 seconds.\n", 589 | "Processed 21000000 lines in 12.1932954788208 seconds.\n", 590 | "Processed 22000000 lines in 12.227113723754883 seconds.\n", 591 | "Processed 23000000 lines in 12.03664231300354 seconds.\n", 592 | "Processed 24000000 lines in 12.078031539916992 seconds.\n", 593 | "Processed 25000000 lines in 12.105196714401245 seconds.\n", 594 | "Processed 26000000 lines in 11.665601968765259 seconds.\n", 595 | "Processed 27000000 lines in 11.893452167510986 seconds.\n", 596 | "Processed 28000000 lines in 11.871276378631592 seconds.\n", 597 | "Processed 29000000 lines in 11.692375421524048 seconds.\n", 598 | "Processed 30000000 lines in 12.258906602859497 seconds.\n", 599 | "Processed 31000000 lines in 12.105127334594727 seconds.\n", 600 | "Processed 32000000 lines in 12.061408281326294 seconds.\n", 601 | "Processed 33000000 lines in 12.181289196014404 seconds.\n", 602 | "Processed 34000000 lines in 11.72019624710083 seconds.\n", 603 | "Processed 35000000 lines in 12.826728820800781 seconds.\n", 604 | "Processed 36000000 lines in 12.203193187713623 seconds.\n", 605 | "Processed 37000000 lines in 11.541372060775757 seconds.\n", 606 | "Processed 38000000 lines in 12.04323673248291 seconds.\n", 607 | "Processed 39000000 lines in 11.960012674331665 seconds.\n", 608 | "Processed 40000000 lines in 11.814802169799805 seconds.\n", 609 | "Processed 41000000 lines in 11.885330438613892 seconds.\n", 610 | "Processed 42000000 lines in 12.102266073226929 seconds.\n", 611 | "Processed 43000000 lines in 11.970007181167603 seconds.\n", 612 | "Processed 44000000 lines in 11.975599765777588 seconds.\n", 613 | "Processed 45000000 lines in 11.771612167358398 seconds.\n", 614 | "Processed 46000000 lines in 12.05254578590393 seconds.\n", 615 | "Processed 47000000 lines in 12.190344333648682 seconds.\n", 616 | "Processed 48000000 lines in 11.416346073150635 seconds.\n", 617 | "Processed 49000000 lines in 11.948322057723999 seconds.\n", 618 | "Processed 50000000 lines in 12.202114820480347 seconds.\n", 619 | "Processed 51000000 lines in 11.811622858047485 seconds.\n", 620 | "Processed 52000000 lines in 11.958524465560913 seconds.\n", 621 | "Processed 53000000 lines in 11.865950107574463 seconds.\n", 622 | "Processed 54000000 lines in 11.55617380142212 seconds.\n", 623 | "Processed 55000000 lines in 12.0974440574646 seconds.\n", 624 | "Processed 56000000 lines in 11.644142866134644 seconds.\n", 625 | "Processed 57000000 lines in 12.029594898223877 seconds.\n", 626 | "Processed 58000000 lines in 11.755115985870361 seconds.\n", 627 | "Processed 59000000 lines in 11.754723072052002 seconds.\n", 628 | "Processed 60000000 lines in 12.040339946746826 seconds.\n", 629 | "Processed 61000000 lines in 11.977319240570068 seconds.\n", 630 | "Processed 62000000 lines in 11.637598276138306 seconds.\n", 631 | "Processed 63000000 lines in 11.80990219116211 seconds.\n", 632 | "Processed 64000000 lines in 11.804283618927002 seconds.\n", 633 | "Processed 65000000 lines in 11.899480819702148 seconds.\n", 634 | "Processed 66000000 lines in 11.878230333328247 seconds.\n", 635 | "Processed 67000000 lines in 12.023569583892822 seconds.\n", 636 | "Processed 68000000 lines in 11.996032238006592 seconds.\n", 637 | "Processed 69000000 lines in 12.08763313293457 seconds.\n", 638 | "Processed 70000000 lines in 11.769520044326782 seconds.\n", 639 | "Processed 71000000 lines in 11.864135026931763 seconds.\n", 640 | "Processed 72000000 lines in 12.032171726226807 seconds.\n", 641 | "Processed 73000000 lines in 11.752153396606445 seconds.\n", 642 | "Processed 74000000 lines in 11.770246982574463 seconds.\n", 643 | "Processed 75000000 lines in 11.743780374526978 seconds.\n", 644 | "Processed 76000000 lines in 11.704986095428467 seconds.\n", 645 | "Processed 77000000 lines in 11.834059715270996 seconds.\n", 646 | "Processed 78000000 lines in 11.838377952575684 seconds.\n", 647 | "Processed 79000000 lines in 11.960946321487427 seconds.\n", 648 | "Processed 80000000 lines in 12.059160470962524 seconds.\n", 649 | "Processed 81000000 lines in 11.739572525024414 seconds.\n", 650 | "Processed 82000000 lines in 12.112396478652954 seconds.\n", 651 | "Processed 83000000 lines in 11.472449779510498 seconds.\n", 652 | "Processed 84000000 lines in 11.976158857345581 seconds.\n", 653 | "Processed 85000000 lines in 11.869161128997803 seconds.\n", 654 | "Processed 86000000 lines in 11.441739559173584 seconds.\n", 655 | "Processed 87000000 lines in 12.081352949142456 seconds.\n", 656 | "Processed 88000000 lines in 12.062784671783447 seconds.\n", 657 | "Processed 89000000 lines in 11.772976636886597 seconds.\n", 658 | "Processed 90000000 lines in 11.97042989730835 seconds.\n", 659 | "Processed 91000000 lines in 11.840981245040894 seconds.\n", 660 | "Processed 92000000 lines in 11.739185810089111 seconds.\n", 661 | "Processed 93000000 lines in 11.718203783035278 seconds.\n", 662 | "Processed 94000000 lines in 11.593910455703735 seconds.\n", 663 | "Processed 95000000 lines in 11.967028617858887 seconds.\n", 664 | "Processed 96000000 lines in 11.914409875869751 seconds.\n", 665 | "Processed 97000000 lines in 11.392530679702759 seconds.\n", 666 | "Processed 98000000 lines in 12.27536916732788 seconds.\n", 667 | "Processed 99000000 lines in 12.178623914718628 seconds.\n", 668 | "Processed 100000000 lines in 11.666812896728516 seconds.\n", 669 | "Processed 101000000 lines in 12.084217071533203 seconds.\n", 670 | "Processed 102000000 lines in 11.728784322738647 seconds.\n", 671 | "Processed 103000000 lines in 11.969763040542603 seconds.\n", 672 | "Processed 104000000 lines in 11.896027326583862 seconds.\n", 673 | "Processed 105000000 lines in 11.9878089427948 seconds.\n", 674 | "Processed 106000000 lines in 11.979403734207153 seconds.\n", 675 | "Processed 107000000 lines in 12.242844820022583 seconds.\n", 676 | "Processed 108000000 lines in 11.823075771331787 seconds.\n", 677 | "Processed 109000000 lines in 11.941327571868896 seconds.\n", 678 | "Processed 110000000 lines in 11.964528322219849 seconds.\n", 679 | "Processed 111000000 lines in 11.766153573989868 seconds.\n", 680 | "Processed 112000000 lines in 11.979164600372314 seconds.\n", 681 | "Processed 113000000 lines in 11.586692571640015 seconds.\n", 682 | "Processed 114000000 lines in 11.805408954620361 seconds.\n", 683 | "Processed 115000000 lines in 12.127535820007324 seconds.\n", 684 | "Processed 116000000 lines in 11.66924786567688 seconds.\n", 685 | "Processed 117000000 lines in 11.909772872924805 seconds.\n", 686 | "Processed 118000000 lines in 12.112474203109741 seconds.\n", 687 | "Processed 119000000 lines in 11.732733488082886 seconds.\n", 688 | "Processed 120000000 lines in 11.751224040985107 seconds.\n", 689 | "Processed 121000000 lines in 11.971590280532837 seconds.\n", 690 | "Processed 122000000 lines in 11.635748386383057 seconds.\n", 691 | "Processed 123000000 lines in 11.804076194763184 seconds.\n", 692 | "Processed 124000000 lines in 11.829573154449463 seconds.\n", 693 | "Processed 125000000 lines in 11.57503366470337 seconds.\n", 694 | "Processed 126000000 lines in 11.492624521255493 seconds.\n", 695 | "Processed 127000000 lines in 11.298207759857178 seconds.\n", 696 | "Processed 128000000 lines in 11.433485984802246 seconds.\n", 697 | "Processed 0 lines in 0.00020456314086914062 seconds.\n", 698 | "Processed 1000000 lines in 10.462962627410889 seconds.\n", 699 | "Processed 2000000 lines in 9.95208740234375 seconds.\n", 700 | "Processed 3000000 lines in 9.9474937915802 seconds.\n", 701 | "Processed 4000000 lines in 10.263622283935547 seconds.\n", 702 | "Processed 5000000 lines in 11.480395078659058 seconds.\n", 703 | "Processed 6000000 lines in 11.746907949447632 seconds.\n", 704 | "Processed 7000000 lines in 11.462883472442627 seconds.\n", 705 | "Processed 8000000 lines in 11.825155019760132 seconds.\n", 706 | "Processed 9000000 lines in 11.741087198257446 seconds.\n", 707 | "Processed 10000000 lines in 11.709346532821655 seconds.\n", 708 | "Processed 11000000 lines in 11.97491717338562 seconds.\n", 709 | "Processed 12000000 lines in 12.119851112365723 seconds.\n", 710 | "Processed 13000000 lines in 11.898428440093994 seconds.\n", 711 | "Processed 14000000 lines in 12.100630760192871 seconds.\n", 712 | "Processed 15000000 lines in 12.112005949020386 seconds.\n", 713 | "Processed 16000000 lines in 12.011102676391602 seconds.\n", 714 | "Processed 17000000 lines in 12.529447078704834 seconds.\n", 715 | "Processed 18000000 lines in 12.218099117279053 seconds.\n", 716 | "Processed 19000000 lines in 12.107082605361938 seconds.\n", 717 | "Processed 20000000 lines in 12.4843008518219 seconds.\n", 718 | "Processed 21000000 lines in 12.455096244812012 seconds.\n", 719 | "Processed 22000000 lines in 11.872814655303955 seconds.\n", 720 | "Processed 23000000 lines in 12.276739597320557 seconds.\n", 721 | "Processed 24000000 lines in 11.623926639556885 seconds.\n", 722 | "Processed 25000000 lines in 12.11262035369873 seconds.\n", 723 | "Processed 26000000 lines in 12.29214859008789 seconds.\n", 724 | "Processed 27000000 lines in 11.742772579193115 seconds.\n", 725 | "Processed 28000000 lines in 11.998782396316528 seconds.\n", 726 | "Processed 29000000 lines in 11.92184042930603 seconds.\n", 727 | "Processed 30000000 lines in 11.926289558410645 seconds.\n", 728 | "Processed 31000000 lines in 11.925652265548706 seconds.\n", 729 | "Processed 32000000 lines in 11.967062711715698 seconds.\n", 730 | "Processed 33000000 lines in 11.953768730163574 seconds.\n", 731 | "Processed 34000000 lines in 12.165066957473755 seconds.\n", 732 | "Processed 35000000 lines in 12.576435565948486 seconds.\n", 733 | "Processed 36000000 lines in 11.860587120056152 seconds.\n", 734 | "Processed 37000000 lines in 11.94038438796997 seconds.\n", 735 | "Processed 38000000 lines in 11.842467069625854 seconds.\n", 736 | "Processed 39000000 lines in 12.158400774002075 seconds.\n", 737 | "Processed 40000000 lines in 11.975207567214966 seconds.\n", 738 | "Processed 41000000 lines in 11.844210386276245 seconds.\n", 739 | "Processed 42000000 lines in 12.002034902572632 seconds.\n", 740 | "Processed 43000000 lines in 12.023306846618652 seconds.\n", 741 | "Processed 44000000 lines in 12.134228467941284 seconds.\n", 742 | "Processed 45000000 lines in 11.975858211517334 seconds.\n", 743 | "Processed 46000000 lines in 11.73196029663086 seconds.\n", 744 | "Processed 47000000 lines in 12.01955270767212 seconds.\n", 745 | "Processed 48000000 lines in 11.939664125442505 seconds.\n", 746 | "Processed 49000000 lines in 11.695724964141846 seconds.\n", 747 | "Processed 50000000 lines in 12.293793201446533 seconds.\n", 748 | "Processed 51000000 lines in 12.177726745605469 seconds.\n", 749 | "Processed 52000000 lines in 11.794549226760864 seconds.\n", 750 | "Processed 53000000 lines in 12.090079307556152 seconds.\n", 751 | "Processed 54000000 lines in 11.518725633621216 seconds.\n", 752 | "Processed 55000000 lines in 12.311357021331787 seconds.\n", 753 | "Processed 56000000 lines in 11.964573383331299 seconds.\n", 754 | "Processed 57000000 lines in 11.741966962814331 seconds.\n", 755 | "Processed 58000000 lines in 11.874887704849243 seconds.\n", 756 | "Processed 59000000 lines in 12.559490203857422 seconds.\n", 757 | "Processed 60000000 lines in 12.336033582687378 seconds.\n", 758 | "Processed 61000000 lines in 11.984862089157104 seconds.\n", 759 | "Processed 62000000 lines in 11.863746166229248 seconds.\n", 760 | "Processed 63000000 lines in 11.452987432479858 seconds.\n", 761 | "Processed 64000000 lines in 12.267062425613403 seconds.\n", 762 | "Processed 65000000 lines in 11.617954730987549 seconds.\n", 763 | "Processed 66000000 lines in 11.970846891403198 seconds.\n", 764 | "Processed 67000000 lines in 12.245222330093384 seconds.\n", 765 | "Processed 68000000 lines in 11.520379543304443 seconds.\n", 766 | "Processed 69000000 lines in 11.980661630630493 seconds.\n", 767 | "Processed 70000000 lines in 12.064447402954102 seconds.\n", 768 | "Processed 71000000 lines in 11.574032068252563 seconds.\n", 769 | "Processed 72000000 lines in 11.813563585281372 seconds.\n", 770 | "Processed 73000000 lines in 12.102405786514282 seconds.\n", 771 | "Processed 74000000 lines in 11.42347764968872 seconds.\n", 772 | "Processed 75000000 lines in 12.1208655834198 seconds.\n", 773 | "Processed 76000000 lines in 11.680182695388794 seconds.\n", 774 | "Processed 77000000 lines in 11.763726949691772 seconds.\n", 775 | "Processed 78000000 lines in 12.015680074691772 seconds.\n", 776 | "Processed 79000000 lines in 11.733760118484497 seconds.\n", 777 | "Processed 80000000 lines in 11.967881441116333 seconds.\n", 778 | "Processed 81000000 lines in 12.108114242553711 seconds.\n", 779 | "Processed 82000000 lines in 11.555633306503296 seconds.\n", 780 | "Processed 83000000 lines in 11.863751888275146 seconds.\n", 781 | "Processed 84000000 lines in 12.066988229751587 seconds.\n", 782 | "Processed 85000000 lines in 11.336068630218506 seconds.\n", 783 | "Processed 86000000 lines in 11.733604192733765 seconds.\n", 784 | "Processed 87000000 lines in 11.556889295578003 seconds.\n", 785 | "Processed 88000000 lines in 11.884316205978394 seconds.\n", 786 | "Processed 89000000 lines in 11.912233352661133 seconds.\n", 787 | "Processed 90000000 lines in 11.863785982131958 seconds.\n", 788 | "Processed 91000000 lines in 11.709333419799805 seconds.\n", 789 | "Processed 92000000 lines in 11.702888488769531 seconds.\n", 790 | "Processed 93000000 lines in 11.484879732131958 seconds.\n", 791 | "Processed 94000000 lines in 11.775110721588135 seconds.\n", 792 | "Processed 95000000 lines in 11.34738540649414 seconds.\n", 793 | "Processed 96000000 lines in 11.901907920837402 seconds.\n", 794 | "Processed 97000000 lines in 11.836457252502441 seconds.\n", 795 | "Processed 98000000 lines in 11.554369688034058 seconds.\n", 796 | "Processed 99000000 lines in 12.211972713470459 seconds.\n", 797 | "Processed 100000000 lines in 11.986082792282104 seconds.\n", 798 | "Processed 101000000 lines in 11.917129278182983 seconds.\n", 799 | "Processed 102000000 lines in 11.970086097717285 seconds.\n", 800 | "Processed 103000000 lines in 11.64471960067749 seconds.\n", 801 | "Processed 104000000 lines in 11.861784219741821 seconds.\n", 802 | "Processed 105000000 lines in 12.029907941818237 seconds.\n", 803 | "Processed 106000000 lines in 11.730420589447021 seconds.\n", 804 | "Processed 107000000 lines in 12.291051626205444 seconds.\n", 805 | "Processed 108000000 lines in 12.040540218353271 seconds.\n", 806 | "Processed 109000000 lines in 11.878763437271118 seconds.\n", 807 | "Processed 110000000 lines in 11.9847252368927 seconds.\n", 808 | "Processed 111000000 lines in 11.982088088989258 seconds.\n", 809 | "Processed 112000000 lines in 11.57691240310669 seconds.\n", 810 | "Processed 113000000 lines in 11.921887636184692 seconds.\n", 811 | "Processed 114000000 lines in 11.763331890106201 seconds.\n", 812 | "Processed 115000000 lines in 11.683130025863647 seconds.\n", 813 | "Processed 116000000 lines in 11.996730089187622 seconds.\n", 814 | "Processed 117000000 lines in 11.809902667999268 seconds.\n", 815 | "Processed 118000000 lines in 11.833222150802612 seconds.\n", 816 | "Processed 119000000 lines in 12.056010246276855 seconds.\n", 817 | "Processed 120000000 lines in 11.568624258041382 seconds.\n", 818 | "Processed 121000000 lines in 11.771402359008789 seconds.\n", 819 | "Processed 122000000 lines in 11.952086687088013 seconds.\n", 820 | "Processed 123000000 lines in 11.53704047203064 seconds.\n", 821 | "Processed 124000000 lines in 12.003801584243774 seconds.\n", 822 | "Processed 125000000 lines in 11.643650531768799 seconds.\n", 823 | "Processed 126000000 lines in 11.146406173706055 seconds.\n", 824 | "Processed 127000000 lines in 11.41442084312439 seconds.\n", 825 | "Processed 128000000 lines in 11.489405870437622 seconds.\n", 826 | "Processed 0 lines in 0.00021386146545410156 seconds.\n", 827 | "Processed 1000000 lines in 10.371429204940796 seconds.\n", 828 | "Processed 2000000 lines in 9.91352367401123 seconds.\n", 829 | "Processed 3000000 lines in 10.065481424331665 seconds.\n", 830 | "Processed 4000000 lines in 9.885550498962402 seconds.\n", 831 | "Processed 5000000 lines in 11.731579065322876 seconds.\n", 832 | "Processed 6000000 lines in 11.536762714385986 seconds.\n", 833 | "Processed 7000000 lines in 11.319538831710815 seconds.\n", 834 | "Processed 8000000 lines in 11.839346170425415 seconds.\n", 835 | "Processed 9000000 lines in 11.698782920837402 seconds.\n", 836 | "Processed 10000000 lines in 11.682351112365723 seconds.\n", 837 | "Processed 11000000 lines in 11.910801410675049 seconds.\n", 838 | "Processed 12000000 lines in 11.96164059638977 seconds.\n", 839 | "Processed 13000000 lines in 12.114214658737183 seconds.\n", 840 | "Processed 14000000 lines in 11.952473402023315 seconds.\n", 841 | "Processed 15000000 lines in 11.936307191848755 seconds.\n", 842 | "Processed 16000000 lines in 12.195603609085083 seconds.\n", 843 | "Processed 17000000 lines in 12.795983076095581 seconds.\n", 844 | "Processed 18000000 lines in 11.953816413879395 seconds.\n", 845 | "Processed 19000000 lines in 12.422369480133057 seconds.\n", 846 | "Processed 20000000 lines in 12.02605390548706 seconds.\n", 847 | "Processed 21000000 lines in 12.616049528121948 seconds.\n", 848 | "Processed 22000000 lines in 12.22676396369934 seconds.\n", 849 | "Processed 23000000 lines in 12.08490252494812 seconds.\n", 850 | "Processed 24000000 lines in 12.117879629135132 seconds.\n", 851 | "Processed 25000000 lines in 11.85872745513916 seconds.\n", 852 | "Processed 26000000 lines in 11.914147138595581 seconds.\n", 853 | "Processed 27000000 lines in 11.900719404220581 seconds.\n", 854 | "Processed 28000000 lines in 12.067522525787354 seconds.\n", 855 | "Processed 29000000 lines in 11.711101055145264 seconds.\n", 856 | "Processed 30000000 lines in 12.320088624954224 seconds.\n", 857 | "Processed 31000000 lines in 11.749680280685425 seconds.\n", 858 | "Processed 32000000 lines in 12.41182827949524 seconds.\n", 859 | "Processed 33000000 lines in 12.011333227157593 seconds.\n", 860 | "Processed 34000000 lines in 11.781742572784424 seconds.\n", 861 | "Processed 35000000 lines in 12.85522723197937 seconds.\n", 862 | "Processed 36000000 lines in 11.992290735244751 seconds.\n", 863 | "Processed 37000000 lines in 11.609273433685303 seconds.\n", 864 | "Processed 38000000 lines in 12.125556707382202 seconds.\n", 865 | "Processed 39000000 lines in 11.991265058517456 seconds.\n", 866 | "Processed 40000000 lines in 11.614512920379639 seconds.\n", 867 | "Processed 41000000 lines in 12.132987976074219 seconds.\n", 868 | "Processed 42000000 lines in 11.835170030593872 seconds.\n", 869 | "Processed 43000000 lines in 12.116438388824463 seconds.\n", 870 | "Processed 44000000 lines in 12.135698556900024 seconds.\n", 871 | "Processed 45000000 lines in 11.884912490844727 seconds.\n", 872 | "Processed 46000000 lines in 11.869536876678467 seconds.\n", 873 | "Processed 47000000 lines in 12.339436531066895 seconds.\n", 874 | "Processed 48000000 lines in 11.496733665466309 seconds.\n", 875 | "Processed 49000000 lines in 11.85990595817566 seconds.\n", 876 | "Processed 50000000 lines in 12.67507815361023 seconds.\n", 877 | "Processed 51000000 lines in 11.64052939414978 seconds.\n", 878 | "Processed 52000000 lines in 11.800786018371582 seconds.\n", 879 | "Processed 53000000 lines in 11.819554567337036 seconds.\n", 880 | "Processed 54000000 lines in 11.866558074951172 seconds.\n", 881 | "Processed 55000000 lines in 12.04162073135376 seconds.\n", 882 | "Processed 56000000 lines in 11.898288488388062 seconds.\n", 883 | "Processed 57000000 lines in 12.073296785354614 seconds.\n", 884 | "Processed 58000000 lines in 11.88059949874878 seconds.\n", 885 | "Processed 59000000 lines in 11.70943284034729 seconds.\n", 886 | "Processed 60000000 lines in 12.18765926361084 seconds.\n", 887 | "Processed 61000000 lines in 11.553351163864136 seconds.\n", 888 | "Processed 62000000 lines in 11.97730278968811 seconds.\n", 889 | "Processed 63000000 lines in 11.8502676486969 seconds.\n", 890 | "Processed 64000000 lines in 11.81417727470398 seconds.\n", 891 | "Processed 65000000 lines in 12.083797216415405 seconds.\n", 892 | "Processed 66000000 lines in 11.995069742202759 seconds.\n", 893 | "Processed 67000000 lines in 11.977404594421387 seconds.\n", 894 | "Processed 68000000 lines in 11.837334632873535 seconds.\n", 895 | "Processed 69000000 lines in 12.076175451278687 seconds.\n", 896 | "Processed 70000000 lines in 11.864582777023315 seconds.\n", 897 | "Processed 71000000 lines in 11.84519910812378 seconds.\n", 898 | "Processed 72000000 lines in 11.598612070083618 seconds.\n", 899 | "Processed 73000000 lines in 12.174880027770996 seconds.\n", 900 | "Processed 74000000 lines in 11.744898319244385 seconds.\n", 901 | "Processed 75000000 lines in 11.774956941604614 seconds.\n", 902 | "Processed 76000000 lines in 12.019569158554077 seconds.\n", 903 | "Processed 77000000 lines in 11.80133605003357 seconds.\n", 904 | "Processed 78000000 lines in 11.841987371444702 seconds.\n", 905 | "Processed 79000000 lines in 11.878009557723999 seconds.\n", 906 | "Processed 80000000 lines in 11.786965131759644 seconds.\n", 907 | "Processed 81000000 lines in 11.597920417785645 seconds.\n", 908 | "Processed 82000000 lines in 12.385830879211426 seconds.\n", 909 | "Processed 83000000 lines in 11.53875207901001 seconds.\n", 910 | "Processed 84000000 lines in 11.96531891822815 seconds.\n", 911 | "Processed 85000000 lines in 11.732539892196655 seconds.\n", 912 | "Processed 86000000 lines in 11.476588487625122 seconds.\n", 913 | "Processed 87000000 lines in 11.847708702087402 seconds.\n", 914 | "Processed 88000000 lines in 12.041157245635986 seconds.\n", 915 | "Processed 89000000 lines in 11.776954889297485 seconds.\n", 916 | "Processed 90000000 lines in 11.909484386444092 seconds.\n", 917 | "Processed 91000000 lines in 11.71180009841919 seconds.\n", 918 | "Processed 92000000 lines in 11.516483306884766 seconds.\n", 919 | "Processed 93000000 lines in 11.727542161941528 seconds.\n", 920 | "Processed 94000000 lines in 11.458016395568848 seconds.\n", 921 | "Processed 95000000 lines in 11.830156087875366 seconds.\n", 922 | "Processed 96000000 lines in 11.930320739746094 seconds.\n", 923 | "Processed 97000000 lines in 11.60464596748352 seconds.\n", 924 | "Processed 98000000 lines in 12.019718885421753 seconds.\n", 925 | "Processed 99000000 lines in 12.29069447517395 seconds.\n", 926 | "Processed 100000000 lines in 11.789185762405396 seconds.\n", 927 | "Processed 101000000 lines in 12.126100301742554 seconds.\n", 928 | "Processed 102000000 lines in 11.912652969360352 seconds.\n", 929 | "Processed 103000000 lines in 11.661912679672241 seconds.\n", 930 | "Processed 104000000 lines in 12.02697467803955 seconds.\n", 931 | "Processed 105000000 lines in 11.789957523345947 seconds.\n", 932 | "Processed 106000000 lines in 12.0976243019104 seconds.\n", 933 | "Processed 107000000 lines in 12.22239875793457 seconds.\n", 934 | "Processed 108000000 lines in 11.693696022033691 seconds.\n", 935 | "Processed 109000000 lines in 11.897872924804688 seconds.\n", 936 | "Processed 110000000 lines in 11.835729360580444 seconds.\n", 937 | "Processed 111000000 lines in 11.6429443359375 seconds.\n", 938 | "Processed 112000000 lines in 11.99439287185669 seconds.\n", 939 | "Processed 113000000 lines in 11.529836654663086 seconds.\n", 940 | "Processed 114000000 lines in 11.98662281036377 seconds.\n", 941 | "Processed 115000000 lines in 12.019933223724365 seconds.\n", 942 | "Processed 116000000 lines in 11.736188411712646 seconds.\n", 943 | "Processed 117000000 lines in 11.98626971244812 seconds.\n", 944 | "Processed 118000000 lines in 12.186249494552612 seconds.\n", 945 | "Processed 119000000 lines in 11.818801879882812 seconds.\n", 946 | "Processed 120000000 lines in 12.083193063735962 seconds.\n", 947 | "Processed 121000000 lines in 11.582455158233643 seconds.\n", 948 | "Processed 122000000 lines in 12.037126779556274 seconds.\n", 949 | "Processed 123000000 lines in 11.726020336151123 seconds.\n", 950 | "Processed 124000000 lines in 11.839289426803589 seconds.\n", 951 | "Processed 125000000 lines in 11.605871200561523 seconds.\n", 952 | "Processed 126000000 lines in 11.548797607421875 seconds.\n", 953 | "Processed 127000000 lines in 11.143155574798584 seconds.\n", 954 | "Processed 128000000 lines in 11.692105054855347 seconds.\n", 955 | "Time taken: 11547.674425840378\n" 956 | ] 957 | } 958 | ], 959 | "source": [ 960 | "filename='../train.csv'\n", 961 | "password_list = PasswordRetriever(filename)\n", 962 | "start = time.time()\n", 963 | "trained_model = FastText(password_list, size=SIZE, min_count=min_count, workers=12,\n", 964 | " negative=negative, sample=subsampling, window=20,\n", 965 | " min_n=min_n, max_n=max_n)\n", 966 | "end = time.time()\n", 967 | "print(\"Time taken: {}\".format(end - start))" 968 | ] 969 | }, 970 | { 971 | "cell_type": "markdown", 972 | "metadata": {}, 973 | "source": [ 974 | "### 3.3 Saving the model" 975 | ] 976 | }, 977 | { 978 | "cell_type": "markdown", 979 | "metadata": {}, 980 | "source": [ 981 | "Finally, the trained model is saved as `.bin`." 982 | ] 983 | }, 984 | { 985 | "cell_type": "code", 986 | "execution_count": 10, 987 | "metadata": {}, 988 | "outputs": [], 989 | "source": [ 990 | "from gensim.models.fasttext import save_facebook_model" 991 | ] 992 | }, 993 | { 994 | "cell_type": "code", 995 | "execution_count": 13, 996 | "metadata": {}, 997 | "outputs": [ 998 | { 999 | "name": "stdout", 1000 | "output_type": "stream", 1001 | "text": [ 1002 | "Model saved successfully.\n" 1003 | ] 1004 | } 1005 | ], 1006 | "source": [ 1007 | "save_facebook_model(trained_model, \"model_password_similarity.bin\")\n", 1008 | "print(\"Model saved successfully.\")" 1009 | ] 1010 | }, 1011 | { 1012 | "cell_type": "markdown", 1013 | "metadata": {}, 1014 | "source": [ 1015 | "## 4. Compressing the model" 1016 | ] 1017 | }, 1018 | { 1019 | "cell_type": "markdown", 1020 | "metadata": {}, 1021 | "source": [ 1022 | "The trained model has 4.8GB. There are some problems about the size:\n", 1023 | "- Too much space occupied in memory.\n", 1024 | "- It is harder to use the model in client/server architectures. Everyone should use this model, which can be sent as a payload. Embeddings are not reversible, and they guarantee password anonymization.\n", 1025 | "\n", 1026 | "For these reasons, `compress_fasttext` is used." 1027 | ] 1028 | }, 1029 | { 1030 | "cell_type": "code", 1031 | "execution_count": 1, 1032 | "metadata": {}, 1033 | "outputs": [], 1034 | "source": [ 1035 | "import gensim\n", 1036 | "import compress_fasttext\n", 1037 | "# from gensim.models.fasttext import load_facebook_vectors" 1038 | ] 1039 | }, 1040 | { 1041 | "cell_type": "markdown", 1042 | "metadata": {}, 1043 | "source": [ 1044 | " In order to obtain a compressed model, without impacting significantly on performances, _product quantitation_ and _feature selection_ are applied.\n", 1045 | " \n", 1046 | " - _Feature selection_ is the process of selecting a subset of relevant features for use in model construction or in other words, the selection of the most important features.\n", 1047 | "\n", 1048 | " - _Product quantization_ is a particolar type of _vector quantization_, a lossy compression technique used in speech and image coding. A product quantizer can generate anexponentially large codebook at very low memory/time cost." 1049 | ] 1050 | }, 1051 | { 1052 | "cell_type": "code", 1053 | "execution_count": 2, 1054 | "metadata": {}, 1055 | "outputs": [], 1056 | "source": [ 1057 | "big_model = gensim.models.fasttext.load_facebook_vectors('model_password_similarity.bin')\n", 1058 | "small_model = compress_fasttext.prune_ft_freq(big_model, pq=True)\n", 1059 | "small_model.save('compressed_model')" 1060 | ] 1061 | }, 1062 | { 1063 | "cell_type": "markdown", 1064 | "metadata": {}, 1065 | "source": [ 1066 | "The compressed_model is 20MB." 1067 | ] 1068 | }, 1069 | { 1070 | "cell_type": "markdown", 1071 | "metadata": {}, 1072 | "source": [ 1073 | "## References\n", 1074 | "[1] [Gensim FastText documentation](https://radimrehurek.com/gensim/models/fasttext.html)\n", 1075 | "\n", 1076 | "[2] [Differences between cbow and skipgram](https://fasttext.cc/docs/en/unsupervised-tutorial.html)\n", 1077 | "\n", 1078 | "[3] [Negative sampling](http://mccormickml.com/2017/01/11/word2vec-tutorial-part-2-negative-sampling/)\n", 1079 | "\n", 1080 | "[4] [Compress FastText package](https://pypi.org/project/compress-fasttext/)\n", 1081 | "\n", 1082 | "[5] [Feature selection](https://towardsdatascience.com/feature-selection-and-dimensionality-reduction-f488d1a035de)\n", 1083 | "\n", 1084 | "[6] [Product quantization](https://www.microsoft.com/en-us/research/wp-content/uploads/2013/11/pami13opq.pdf)\n", 1085 | "\n", 1086 | "[7] [PPSM description from the paper \"Beyond Credential Stuffing: Password Similarity Models using Neural Networks\"](https://www.cs.cornell.edu/~rahul/papers/ppsm.pdf)\n", 1087 | "\n", 1088 | "[8] [PPSM repository from the paper \"Beyond Credential Stuffing: Password Similarity Models using Neural Networks\"](https://github.com/Bijeeta/credtweak)" 1089 | ] 1090 | } 1091 | ], 1092 | "metadata": { 1093 | "kernelspec": { 1094 | "display_name": "Python 3", 1095 | "language": "python", 1096 | "name": "python3" 1097 | }, 1098 | "language_info": { 1099 | "codemirror_mode": { 1100 | "name": "ipython", 1101 | "version": 3 1102 | }, 1103 | "file_extension": ".py", 1104 | "mimetype": "text/x-python", 1105 | "name": "python", 1106 | "nbconvert_exporter": "python", 1107 | "pygments_lexer": "ipython3", 1108 | "version": "3.8.3" 1109 | } 1110 | }, 1111 | "nbformat": 4, 1112 | "nbformat_minor": 4 1113 | } 1114 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /No_w2kp_PRGraph.py: -------------------------------------------------------------------------------- 1 | # No word2keypress version 2 | import itertools 3 | import sys 4 | import csv 5 | import time 6 | import compress_fasttext 7 | import numpy as np 8 | from matplotlib import pyplot as plt 9 | from collections import OrderedDict 10 | from nltk import edit_distance 11 | 12 | 13 | def leet_code(string: str): 14 | for char in string: 15 | if char == 'a': 16 | string = string.replace('a', '4') 17 | elif char == 'b': 18 | string = string.replace('b', '8') 19 | elif char == 'e': 20 | string = string.replace('e', '3') 21 | elif char == 'l': 22 | string = string.replace('l', '1') 23 | elif char == 'o': 24 | string = string.replace('o', '0') 25 | elif char == 's': 26 | string = string.replace('s', '5') 27 | elif char == 't': 28 | string = string.replace('t', '7') 29 | else: 30 | pass 31 | return string 32 | 33 | 34 | # HEURISTICS 35 | def heuristics(pwd1: str, pwd2: str): 36 | if leet_code(pwd1) == leet_code(pwd2): 37 | return True 38 | if pwd1.lower() == pwd2.lower(): 39 | return True 40 | if edit_distance(pwd1, pwd2, transpositions=True) < 5: 41 | return True 42 | return False 43 | 44 | 45 | def main(): 46 | # Usage: 47 | # python3 PRGraph.py 48 | if len(sys.argv) != 3: 49 | sys.exit("Usage: python3 PRGraph.py ") 50 | filename = sys.argv[1] 51 | compressed_model_file = sys.argv[2] 52 | small_model = compress_fasttext.models.CompressedFastTextKeyedVectors.load(compressed_model_file) 53 | pos_neg_count = OrderedDict() 54 | prec_dict = OrderedDict() 55 | rec_dict = OrderedDict() 56 | 57 | for th in np.arange(0.0, 1.1, 0.1): 58 | pos_neg_count_th = {'TP': 0, 'FP': 0, 'FN': 0} 59 | pos_neg_count[th] = pos_neg_count_th 60 | 61 | with open(filename) as file: 62 | csv_reader = csv.reader(file, delimiter=':') 63 | start_time = time.time() 64 | for i, (user, pass_keyseq_list) in enumerate(csv_reader): 65 | if i % 10000 == 0: 66 | end_time = time.time() 67 | print("Processed {} lines in {} seconds.".format(i, end_time - start_time)) 68 | start_time = end_time 69 | user_pass_list = eval(pass_keyseq_list) 70 | for pwd1, pwd2 in itertools.combinations(user_pass_list, 2): 71 | # Find similarity percentage using the model 72 | sim_score = small_model.similarity(pwd1, pwd2) 73 | ground_truth = heuristics(pwd1, pwd2) 74 | 75 | for th, pos_neg_count_th in pos_neg_count.items(): 76 | bin_sim_score = sim_score > th 77 | if bin_sim_score and ground_truth: 78 | pos_neg_count_th['TP'] += 1 79 | elif bin_sim_score and not ground_truth: 80 | pos_neg_count_th['FP'] += 1 81 | elif not bin_sim_score and ground_truth: 82 | pos_neg_count_th['FN'] += 1 83 | 84 | for th, pos_neg_count_th in pos_neg_count.items(): 85 | th_prec = pos_neg_count_th['TP'] / (pos_neg_count_th['TP'] + pos_neg_count_th['FP']) 86 | th_rec = pos_neg_count_th['TP'] / (pos_neg_count_th['TP'] + pos_neg_count_th['FN']) 87 | prec_dict[th] = th_prec 88 | rec_dict[th] = th_rec 89 | 90 | x, y_p = zip(*prec_dict.items()) 91 | _, y_r = zip(*rec_dict.items()) 92 | 93 | plt.plot(x, y_p, label='Precision') 94 | plt.plot(x, y_r, label='Recall') 95 | plt.legend() 96 | plt.grid() 97 | plt.xticks(np.arange(0.0, 1.1, 0.1)) 98 | plt.yticks(np.arange(0.0, 1.05, 0.05)) 99 | plt.show() 100 | 101 | 102 | if __name__ == '__main__': 103 | main() 104 | 105 | -------------------------------------------------------------------------------- /PasswordRetriever.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import time 3 | 4 | # This class retrieves a list of passwords from the cleaned csv file. 5 | class PasswordRetriever(object): 6 | def __init__(self, filename): 7 | self.filename = filename 8 | 9 | def __iter__(self): 10 | with open(self.filename) as file: 11 | csv_reader = csv.reader(file, delimiter=':') 12 | start_time = time.time() 13 | for i, (user, pass_keyseq_list) in enumerate(csv_reader): 14 | if i % 1000000 == 0: 15 | end_time = time.time() 16 | print("Processed {} lines in {} seconds.".format(i, end_time - start_time)) 17 | start_time = end_time 18 | user_pass_list = eval(pass_keyseq_list) 19 | yield user_pass_list 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # Password Similarity Detection Using Deep Neural Networks 4 |
5 | 6 |
7 | 8 | [![Ask Me Anything!](https://img.shields.io/badge/Ask%20me-anything-1abc9c.svg)](https://github.com/TryKatChup/password-similarity-nlp/issues) 9 | [![Open In Collab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/TryKatChup/password-similarity-nlp/blob/main/FastText_training.ipynb) 10 | [![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/) 11 | [![made-with-Markdown](https://img.shields.io/badge/Made%20with-Markdown-1f425f.svg)](http://commonmark.org) 12 | [![Open Source Love png1](https://badges.frapsoft.com/os/v1/open-source.png?v=103)](https://github.com/ellerbrock/open-source-badges/) 13 | [![GPLv3 license](https://img.shields.io/badge/License-GPLv3-blue.svg)](http://perso.crans.org/besson/LICENSE.html) 14 |
15 | 16 | 17 |
18 | 19 |
20 | 21 | # Table of Contents 22 | - [Introduction](#introduction) 23 | - [Data pre-processing](#data-pre-processing) 24 | - [Word2keypress](#word2keypress) 25 | - [Splitting dataset](#splitting-dataset) 26 | - [Training FastText](#training-fasttext) 27 | - [Word2Vec](#word2vec) 28 | - [FastText](#fasttext) 29 | - [Environment setup](#environment-setup) 30 | - [FastText parameters](#fasttext-parameters) 31 | - [Saving the model](#saving-the-model) 32 | - [More trainings](#more-trainings) 33 | - [Compressing the model](#compressing-the-model) 34 | - [Evaluating the model](#evaluating-the-model) 35 | - [Euristhics](#euristhics) 36 | - [Ground truth and prediction](#ground-truth-and-prediction) 37 | - [Precision and recall](#precision-and-recall) 38 | - [Comparing the results of the models](#comparing-the-results-of-the-models) 39 | - [Bijeeta et al. model issues](#bijeeta-et-al-model-issues) 40 | - [Graphic representation of words distance](#graphic-representation-of-words-distance) 41 | 42 | --- 43 | # Introduction 44 | 45 | Nowadays people tend to create more profiles or change password of their current profiles for security reasons. Existent passwords and literature-based words have a great impact on the candidate password. This could be a risk for the user privacy. For example, an user has the password `mum77` and he/she wants to create a new account for a different website. A candidate password could be `mommy1977`, which is a variation of `mum77` and it more risky if an attacker has discovered the first password in a leak. 46 | 47 | The purpose of this project is to give a feedback about password similarity between the new password and the old one using Deep Neural Networks. 48 | As a reference, a [scientific article published at IEEE Symposium on Security and Privacy 2019](https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=8835247was) chosen. Then the entire architecture was reimplemented and improved, and a comparison between the obtained results and the case study was made. 49 | 50 | --- 51 | # Data pre-processing 52 | **File:** [`preparing_dataset.py`](https://github.com/TryKatChup/password-similarity-nlp/blob/main/preparing_dataset.py) 53 | 54 | First of all I used a compilation of password leaks containing 1.4 billion email-password pairs from the Deep Web. Further operations were applied on the dataset: 55 | - Passwords longer than 30 characters or shorter than 4 removal. 56 | - Non ASCII printable characters in password removal. 57 | - Bot (which are recognisable by the same mail used more than 100 times) removal. 58 | - HEX passwords (identified by `$HEX[]`) and `\x` removal. 59 | - HTML char set removal, for example: 60 | - `>`; 61 | - `&ge`; 62 | - `<`; 63 | - `&le`; 64 | - `&#` (HTML entity code); 65 | - `amp`. 66 | 67 | - Due to the impossibility of similarity detection, accounts with less than 2 password were removed. 68 | 69 | After that, two dataset were build: 70 | 71 | - The first one, according with Bijeeta et alii, contains all the passwords in key-presses format (using the `word2keypress` package). 72 | - The second one contains all the passwords as they are. 73 | 74 | The filtered datasets were saved in two `.csv` files in this format: 75 | - in the first dataset: `sample@gmail.com:["’97314348’", "’voyager1’"]` 76 | - in the second dataset: `sample@gmail.com:["’97314348’", "’voyager!’"]` 77 | 78 | ## Word2keypress 79 | 80 | Every password in the first dataset was translated in a keypress sequence on an ANSI american keyboard: 81 | - Every capital letter was represented by `` (the `SHIFT` key) before the lowercase version. 82 | 83 | e.g. `Hello -> hello` 84 | - If there is a sequence of consecutive capital letters, followed by lowercase letters, the `` tag (the `CAPS LOCK` key) is inserted _before_ and _after_ the sequence, which will be represented by lowercase letters. 85 | 86 | e.g. `Password -> password` 87 | - If a sequence of capital letters ends at the end of the word, the `` tag wil be placed before the sequence. 88 | 89 | e.g. ```PASSWORD -> password 90 | passWORD -> password``` 91 | 92 | - If a password contains ASCII 128 special characters, the `` tag will be placed before the special character, which is translated as `SHIFT + ` 93 | 94 | e.g. ```PASSWORD! -> password1 95 | Hello@!! -> hello211``` 96 | 97 |
98 | 99 |
100 | 101 | ## Splitting dataset 102 | **File:** [`split_dataset.py`](https://github.com/TryKatChup/password-similarity-nlp/blob/main/split_dataset.py) 103 | 104 | Both datasets are splitted in training set (which is 90% of the original dataset) and test set (the remaining 10% of the original dataset). 105 | 106 | --- 107 | # Training FastText 108 | **File:** [`FastText_training.ipynb`](https://github.com/TryKatChup/password-similarity-nlp/blob/main/FastText_training.ipynb) **and** [`PasswordRetriever.py`](https://github.com/TryKatChup/password-similarity-nlp/blob/main/PasswordRetriever.py) 109 | 110 | In this file FastText will be trained based on the given training set. 111 | In order to understand better `Training dataset.py` and FastText, Word2Vec is briefly introduced. 112 | 113 | ## Word2Vec 114 | Word2Vec is a set of architectural and optimization models which learn word embeddings from a large dataset, using deep neural networks. 115 | A model trained with Word2Vec can detect similar words (based on context) thanks to _cosine similarity_. 116 | 117 | Word2Vec is based on two architectures: 118 | - **CBOW** (continuous bag of words): the main purpose is to combine the representation of surrounding words, in order to predict the word in the middle. 119 | - **Skip-gram:** similar to CBOW, except for the word in the middle, which is used to predict words related to the same context. 120 | 121 | CBOW is faster and effective with larger dataset, however, despite the greater complexity, Skip-gram is capable to find _out of dictionary_ words for smaller datasets. 122 | 123 |
124 | 125 |
126 | 127 | ## FastText 128 | [FastText](https://fasttext.cc/) is a open source library created by Facebook which extends Word2Vec and is capable to learn word representation and sentence classification efficiently. The training is based on password n-grams. 129 | N-grams of a specific word that contains `n` characters are defined as follow: 130 |
131 | 132 |
133 | 134 | For example, the ngrams of the word `world`, with `n_mingram = 1` and `n_maxgram = 5` are: 135 | `world = {{w, o, r, l, d}, {wo, or, rl, ld}, {wor, orl, rld}, {world}}` 136 | 137 | `world` is represented as the subset of substrings with 1 and 5 as respectively minimum and maximum length. 138 | FastText, comparing to Word2Vec, is capable to obtain more _out of dictionary_ words, which are unknown during the training phase. 139 | 140 | ## Environment setup 141 | In order to train the model, [`gensim.FastText`](https://radimrehurek.com/gensim/models/fasttext.html) was used. 142 | [`gensim`](https://radimrehurek.com/gensim/) is a open source and cross-platform python library, with multiple pre-trained word embedding models. 143 | `PasswordRetriever` class extracts all the passwords from the `.csv` preprocessed file. 144 | 145 | ## FastText parameters 146 | ```python 147 | negative = 5 148 | subsampling = 1e-3 149 | min_count = 10 150 | min_n = 2 151 | max_n = 4 152 | SIZE = 200 153 | sg = 1 154 | ``` 155 | In this project _Skip-gram_ model (`sg = 1`) and negative sampling were used: 156 | 157 | - Skip-gram approach is chosen, as the distributed representation of the input word is used to predict the context. Skip-gram model works better with subword information, so it is recommended for learning passwords and rare words in general. 158 | 159 | - Negative sampling makes the training faster. Each training sample updates only a small percentage of the model weights. For larger datasets (like this case) it is recommended to set negative sampling between 2 and 5. 160 | 161 | - The dimension of vectors is set to 200, in order to have train the model faster. Generally it is recommended to have `SIZE = 300`. 162 | 163 | - The `subsampling` ignores the most frequent password (more than 1000 occurrences). 164 | 165 | - `min_count` represents the minimum number of occurences of a password in the training dataset. 166 | 167 | - `min_n` and `max_n` are the number of respectively minimum and maximum n-grams. 168 | 169 | - N-grams are used in statistical natural language processing to predict a word and/or the context of a word. In this case they represent a contiguous sequence of n characters and their purpose is to give subword information. 170 | 171 | - For example a password `w = qwerty` with `min_n = 4` and `m_max = 5`, will have the following n-grams. 172 | `zw = {, }` 173 | 174 | NB `<` and `>` are considered as characters. 175 | 176 | ## Saving the model 177 | Finally, the trained model is saved as `.bin`. 178 | ```python 179 | from gensim.models.fasttext import save_facebook_model 180 | save_facebook_model(trained_model, "model_password_similarity.bin") 181 | print("Model saved successfully.") 182 | ``` 183 | ## More trainings 184 | 185 | 5 models were trained: 186 | - `word2keypress`, `epochs = 5`, `n_mingram = 1` (Bijeeta et al.); 187 | - `word2keypress`, `epochs = 5`, `n_mingram = 2`; 188 | - no `word2keypress`, `epochs = 10`, `n_mingram = 1`; 189 | - no `word2keypress`, `epochs = 10`, `n_mingram = 2`; 190 | - no `word2keypress`, `epochs = 5`, `n_mingram = 2`. 191 | 192 | --- 193 | # Compressing the model 194 | 195 | The trained model is 4.8 GB. There are some problems about the size: 196 | 197 | - Too much space occupied in memory. 198 | - It is harder to use the model in client/server architectures. Everyone should use this model, which can be sent as a payload. Embeddings are not reversible, and they guarantee password anonymization. 199 | 200 | For these reasons, [`compress_fasttext`](https://pypi.org/project/compress-fasttext/) is used. 201 | ```python 202 | import gensim 203 | import compress_fasttext 204 | ``` 205 | 206 | In order to obtain a compressed model, without impacting significantly on performances, product quantitation and feature selection are applied. 207 | 208 | - Feature selection is the process of selecting a subset of relevant features for use in model construction or in other words, the selection of the most important features. 209 | 210 | - Product quantization is a particolar type of vector quantization, a lossy compression technique used in speech and image coding. A product quantizer can generate anexponentially large codebook at very low memory/time cost. 211 | 212 | ``` python 213 | big_model = gensim.models.fasttext.load_facebook_vectors('model_password_similarity.bin') 214 | small_model = compress_fasttext.prune_ft_freq(big_model, pq=True) 215 | small_model.save('compressed_model') 216 | ``` 217 | The compressed_model is 20MB. 218 | 219 | --- 220 | # Evaluating the model 221 | **File:** [`w2kp_PRGraph.py`](https://github.com/TryKatChup/password-similarity-nlp/blob/main/w2kp_PRGraph.py) **and** [`No_w2kp_PRGraph.py`](https://github.com/TryKatChup/password-similarity-nlp/blob/main/No_w2kp_PRGraph.py) 222 | 223 | For the evaluation of the models, compressed versions obtained with product quantization were used. In order to measure any performance differences between the original model and the compressed version, Bijeeta et al. model is chosen, with the following features: 224 | - translation of the sequence of key pressed for the password; 225 | - `min_gram = 1`; 226 | - `max_gram = 4`; 227 | - `epochs = 5`. 228 | 229 | An effective valutation of both model is based on _precision_ and _recall_. 230 | Not remarkable differences were observed: for this reason only the compressed version of the models are considered. 231 |
232 | 233 |
234 | 235 |
236 | Precision and recall in the uncompressed model of Bijeeta et al. 237 |
238 | 239 |

240 | 241 |
242 | 243 |
244 | 245 |
246 | Precision and recall in the compressed model of Bijeeta et al. 247 |
248 | 249 | 250 | ## Euristhics 251 | For a proper evaluation the following euristhics is adopted: 252 | - comparing the password to the lowercase version; 253 | - comparing the password to the uppercase version; 254 | - comparing the password to the `l33t` code version; 255 | - verifing if edit distance is greater than 5. 256 | 257 | ## Ground truth and prediction 258 | Ground truth is the ideal result expected and it is used in order to verify how much correct are model prediction. 259 | The term _prediction_ refers to the model output after the training. It is applied to new data when is required to verify an event probability. 260 | 261 | Ground truth depends on the candidate two passwords and the chosen euristhics, while prediction is obtained thanks to `gensim.similarity` function of the trained model (which is based on cosine similarity). In case of the `work2keypress` model, it is important to convert the candidate two password in key presses (`w2kp_PRGraph.py`). 262 | 263 | 264 | ## Precision and recall 265 | **Precision** represents the number of true positive detected from true positives and false positives. 266 | 267 | **Recall** represents the number of positive elements detected from a set of false negatives and true positives. 268 |
269 | 270 |
271 | 272 | In this case: 273 | - A couple of similar passwords detected correctly represents **true positives** 274 | - A couple of different password detected as similar are **false positives**. 275 | - A couple of similar passwords not detected as similar are **false negatives**. 276 | 277 | In order to find out _precision_ and _recall_ it is important to re-define few concepts, according to [ground truth and prediction subchapter](#ground-truth-and-prediction): 278 | - **True positives (TP)**: its value increments only if both prediction and ground truth have a strictly positive value. 279 | - **False positives (FP)**: its value increments only if ground truth value is zero and if prediction has a strictly positive value. 280 | - **False negatives (FP)**: its value increments only if ground truth value is strictly positive and if prediction value is zero. 281 |
282 | 283 |
284 | 285 | ## Comparing the results of the models 286 | In order to classify passwords, it is necessary to define a threeshold α, which it is chosen considering the best precision and recall values. 287 | 288 | - Model with `word2keypress`, `n_mingram = 1`, `epochs = 5` (Bijeeta et al.): 289 | - α = 0.5: precision ≈ 57%, recall ≈ 95% 290 | - α = 0.6: precision ≈ 67%, recall ≈ 89% 291 | 292 | - Model without `word2keypress`, `n_mingram = 2`, `epochs = 5`: 293 | - α = 0.5: precision ≈ 65%, recall ≈ 95% 294 | - α = 0.6: precision ≈ 77%, recall ≈ 89% 295 | 296 | In this case study, it is more important an higher value of recall. In this way more similar passwords are detected. 297 | It is also important to not have too many false positives identified by couples of password which are different from each other but are considered similar. For this reason I have chosen an higher value of precision, comparing to Bijeeta et al. paper and α = 0.6. 298 | 299 |
300 | 301 |
302 | 303 |
304 | Precision and recall with word2keypress, n_mingram = 1, epochs = 5 (worst model) 305 |
306 | 307 |

308 | 309 |
310 |
311 | 312 |
313 | 314 |
315 | Precision and recall without word2keypress, n_mingram = 2, epochs = 5 (best model). 316 |
317 | 318 | ## Bijeeta et al. model issues 319 | The worst performances were noticed in the Bijeeta et al. model. The main problems are: 320 | - `word2keypress` library translates each character as a key press sequence. When a password is expressed in camel notation, an alternation of capital letters and lowercase letters is present. As a consequence, different passwords in camel notation will be considered similar, because of the repetition of `` and ``. 321 | - Two passwords expressed as key presses like: 322 | - `$1mp@t1c*` which is translated as `41mp2t1c8` 323 | - `#wlng%p*m}` which is translated as `3wlng5p8m[` 324 | will be considered similar. 325 | `SHIFT` is translated as ``: for this reason two passwords which are secure will appear similar. 326 | 327 | - Setting `n_mingram = 1` make the evaluation less precise than using `n_mingram = 2`. 328 | In fact, in passwords, single characters in passwords do not depend on syntactic rules (unlike in english literature). There are multiple factors really different from each other in order to establish a set of rules for the position of a character in a password, so it is impossible to define how a character is placed. 329 | 330 | --- 331 | # Graphic representation of words distance 332 | **File:** [`visualize_embeddings.py`](https://github.com/TryKatChup/password-similarity-nlp/blob/main/visualize_embeddings.py) 333 | 334 | To simplify the comprehension of the project topic, password similarity is represented with a 3-dimensional graphic. [`t-SNE` algorithm](https://scikit-learn.org/stable/modules/generated/sklearn.manifold.TSNE.html) is used to reduce the model dimension from 200 to 3. In the next figure it is possible to see the top 5 most similar passwords to `ipwnedyou` and `numBerOne` and their distances. 335 |
336 | 337 |
338 | -------------------------------------------------------------------------------- /images/3dplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TryKatChup/password-similarity-nlp/c2c1daa33ed713bfabbaf0d5a90b010db499d948/images/3dplot.png -------------------------------------------------------------------------------- /images/US_keyboard_layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TryKatChup/password-similarity-nlp/c2c1daa33ed713bfabbaf0d5a90b010db499d948/images/US_keyboard_layout.png -------------------------------------------------------------------------------- /images/big_model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TryKatChup/password-similarity-nlp/c2c1daa33ed713bfabbaf0d5a90b010db499d948/images/big_model.png -------------------------------------------------------------------------------- /images/cbow_vs_skipgram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TryKatChup/password-similarity-nlp/c2c1daa33ed713bfabbaf0d5a90b010db499d948/images/cbow_vs_skipgram.png -------------------------------------------------------------------------------- /images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TryKatChup/password-similarity-nlp/c2c1daa33ed713bfabbaf0d5a90b010db499d948/images/logo.png -------------------------------------------------------------------------------- /images/nngram_formula.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TryKatChup/password-similarity-nlp/c2c1daa33ed713bfabbaf0d5a90b010db499d948/images/nngram_formula.png -------------------------------------------------------------------------------- /images/no_w2kp_nmingram=2_epochs=5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TryKatChup/password-similarity-nlp/c2c1daa33ed713bfabbaf0d5a90b010db499d948/images/no_w2kp_nmingram=2_epochs=5.png -------------------------------------------------------------------------------- /images/precision_recall_formula.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TryKatChup/password-similarity-nlp/c2c1daa33ed713bfabbaf0d5a90b010db499d948/images/precision_recall_formula.png -------------------------------------------------------------------------------- /images/precisionrecall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TryKatChup/password-similarity-nlp/c2c1daa33ed713bfabbaf0d5a90b010db499d948/images/precisionrecall.png -------------------------------------------------------------------------------- /images/w2kp_nmingram=1_epochs=5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TryKatChup/password-similarity-nlp/c2c1daa33ed713bfabbaf0d5a90b010db499d948/images/w2kp_nmingram=1_epochs=5.png -------------------------------------------------------------------------------- /preparing_dataset.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import os 3 | import sys 4 | from concurrent.futures.thread import ThreadPoolExecutor 5 | from os import listdir 6 | from os.path import isfile, join 7 | from time import time 8 | from word2keypress import Keyboard 9 | 10 | kb = Keyboard() 11 | 12 | 13 | # The function is_valid_password filters password in this way: 14 | # - removes passwords longer than 30 characters or shorter than 4. 15 | # - removes non ASCII printable characters in a password 16 | # - removes bot, which are recognisable by the same mail used more than 100 times. 17 | # - removes HEX passwords (identified by $HEX[]) and \x 18 | # - removes HTML char set 19 | 20 | def is_valid_password(password): 21 | pass_len = len(password) 22 | return 4 < pass_len < 30 and password.isascii() and password.isprintable() and not password.startswith('\\x') \ 23 | and '$HEX' not in password and '<' not in password and '>' not in password \ 24 | and '&le' not in password and '&ge' not in password and '&#' not in password \ 25 | and '&' not in password 26 | 27 | 28 | # The function filter_file filters source, removing mail in this way: 29 | # - mail which appear more than 100 times and less than 2. 30 | # - mail with non-valid password 31 | 32 | # After that the password is converted in a key-press sequence. 33 | # The result will be saved in dest, which is a csv file, in this way: 34 | 35 | # sample@gmail.com: ["'97314348'", "'voyager1'"] 36 | 37 | def filter_file(source, dest): 38 | # Counter of occurrences of the same mail 39 | counter = 0 40 | # temp_list will contain the new line read from source, which will be printed only if 41 | # the email address is not repeated more than 100 times and less than 2 times. 42 | # After the print, the elements in the list will be deleted. 43 | temp_list = [] 44 | # Opening a new csv file with the filtered file 45 | with open(dest, mode='w') as new_file: 46 | new_file_writer = csv.writer(new_file, delimiter=':', quoting=csv.QUOTE_NONE, escapechar='', quotechar='') 47 | # In order to avoid problems and Decode 48 | with open(source, 'r', encoding='utf-8', errors='replace') as f: 49 | for line in f: 50 | split_line = line.strip().split(':') 51 | # If line is valid, continue processing 52 | if len(split_line) == 2: 53 | # Retrieve mail and password 54 | (email, password) = split_line 55 | # Check if current mail is different from the last one read 56 | if len(temp_list) > 0 and email != temp_list[-1][0]: 57 | # Check counter: if true, write elements to CSV 58 | if 2 <= counter < 100: 59 | email_list, password_list = zip(*temp_list) 60 | password_list = [f'{repr(kb.print_keyseq(kb.word_to_keyseq(p)))}' for p in 61 | password_list] # to key-presses + double ticks 62 | password_list_str = f"[{', '.join(password_list)}]" 63 | # Write all elements of the list to file 64 | new_file_writer.writerow([email_list[0], password_list_str]) 65 | counter = 0 66 | temp_list.clear() 67 | # If password is valid, add new tuple to list 68 | if is_valid_password(password): 69 | # Add tuple (email, password) to list and increment counter 70 | temp_list.append(split_line) 71 | counter += 1 72 | 73 | # The last item or the last items with the same email cannot be printed. 74 | # So the last elements will be printed and the list will be cleared 75 | if 2 <= counter < 100: 76 | email_list, password_list = zip(*temp_list) 77 | password_list = [f'\"{repr(kb.print_keyseq(kb.word_to_keyseq(p)))}\"' for p in 78 | password_list] # to key-presses + double ticks 79 | password_list_str = f"[{', '.join(password_list)}]" 80 | # print(email_list[0], password_list_str) 81 | # Write all elements of the list to file 82 | new_file_writer.writerow([email_list[0], password_list_str]) 83 | temp_list.clear() 84 | 85 | 86 | if __name__ == '__main__': 87 | start_time = time() 88 | arguments = sys.argv 89 | if len(arguments) != 3: 90 | print('Usage: python3 filter.py ') 91 | exit(1) 92 | source_dir = arguments[1] 93 | dest_dir = arguments[2] 94 | # if not isdir(source_dir): 95 | # print("error, source directory not found, exiting") 96 | # exit(2) 97 | for file in listdir(source_dir): 98 | source_file = join(source_dir, file) 99 | if isfile(source_file): 100 | if not os.path.isdir(dest_dir): 101 | os.makedirs(dest_dir) 102 | # Creates the file filtered in the specified path and with the same name as filename. 103 | dest_file = os.path.join(dest_dir, file + ".csv") 104 | with ThreadPoolExecutor(max_workers=4) as executor: 105 | executor.submit(filter_file, source_file, dest_file) 106 | stop_time = time() 107 | print(f'Time elapsed: {stop_time - start_time} sec') 108 | -------------------------------------------------------------------------------- /split_dataset.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import csv 3 | import random 4 | 5 | 6 | def main(): 7 | args = sys.argv 8 | if len(args) != 4: 9 | print("Usage: python split_dataset.py SOURCE_FILE TRAIN_DEST_FILE TEST_DEST_FILE") 10 | sys.exit(-1) 11 | 12 | source = args[1] 13 | train_dest = args[2] 14 | test_dest = args[3] 15 | test_chance = 0.1 # IMPORTANT: 0.1 -> 10% of the whole dataset reserved to test 16 | 17 | random.seed(42) # IMPORTANT: fix seed to have reproducible results 18 | with open(source, mode='r') as s_f, open(train_dest, mode='w') as train_f, open(test_dest, mode='w') as test_f: 19 | source_csv_reader = csv.reader(s_f, delimiter=':') 20 | train_csv_writer = csv.writer(train_f, delimiter=':', quoting=csv.QUOTE_NONE, quotechar='', escapechar='') 21 | test_csv_writer = csv.writer(test_f, delimiter=':', quoting=csv.QUOTE_NONE, quotechar='', escapechar='') 22 | 23 | for i, (user, pass_keyseq_list) in enumerate(source_csv_reader): 24 | # print(f'Processing line {i+1}...') 25 | # Apply reservoir sampling 26 | if random.random() > test_chance: 27 | train_csv_writer.writerow([user, pass_keyseq_list]) 28 | else: 29 | test_csv_writer.writerow([user, pass_keyseq_list]) 30 | print('Processing complete!') 31 | 32 | 33 | if __name__ == "__main__": 34 | main() 35 | -------------------------------------------------------------------------------- /visualize_embeddings.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import plotly 3 | import numpy as np 4 | import plotly.graph_objs as go 5 | from MulticoreTSNE import MulticoreTSNE as TSNE 6 | import compress_fasttext 7 | import gensim.downloader as gloader 8 | 9 | 10 | def append_list(sim_passwords, password): 11 | list_of_passwords = [] 12 | 13 | for i in range(len(sim_passwords)): 14 | sim_passwords_list = list(sim_passwords[i]) 15 | sim_passwords_list.append(password) 16 | sim_passwords_tuple = tuple(sim_passwords_list) 17 | list_of_passwords.append(sim_passwords_tuple) 18 | 19 | return list_of_passwords 20 | 21 | 22 | def display_tsne_scatterplot_3D(model, 23 | user_input = None, 24 | words = None, 25 | label = None, 26 | color_map = None, 27 | perplexity = 0, 28 | learning_rate = 0, 29 | iteration = 0, 30 | topn = 5, 31 | sample = 10): 32 | if words == None: 33 | if sample > 0: 34 | words = np.random.choice(list(model.vocab.keys()), sample) 35 | else: 36 | words = [word for word in model.vocab] 37 | word_vectors = np.array([model[w] for w in words]) 38 | 39 | # For 2D, change the three_dim variable into something like two_dim like the following: 40 | # two_dim = TSNE(n_components = 2, random_state=0, perplexity = perplexity, learning_rate = learning_rate, n_iter = iteration).fit_transform(word_vectors)[:,:2] 41 | three_dim = TSNE(n_components=3, random_state=0, perplexity=perplexity, learning_rate=learning_rate, n_iter=iteration, n_jobs=4).fit_transform(word_vectors)[:, :3] 42 | 43 | data = [] 44 | count = 0 45 | for i in range(len(user_input)): 46 | # For 2D, instead of using go.Scatter3d, we need to use go.Scatter and delete the z variable. Also, instead of using 47 | # variable three_dim, use the variable that we have declared earlier (e.g two_dim) 48 | trace = go.Scatter3d( 49 | x=three_dim[count:count + topn, 0], 50 | y=three_dim[count:count + topn, 1], 51 | z=three_dim[count:count + topn, 2], 52 | text=words[count:count + topn], 53 | name=user_input[i], 54 | textposition="top center", 55 | textfont_size=20, 56 | mode='markers+text', 57 | marker={ 58 | 'size': 10, 59 | 'opacity': 0.8, 60 | 'color': 2 61 | } 62 | 63 | ) 64 | 65 | data.append(trace) 66 | count = count+topn 67 | 68 | # For 2D, instead of using go.Scatter3d, we need to use go.Scatter and delete the z variable. Also, instead of using 69 | # variable three_dim, use the variable that we have declared earlier (e.g two_dim) 70 | trace_input = go.Scatter3d( 71 | x=three_dim[count:,0], 72 | y=three_dim[count:,1], 73 | z=three_dim[count:,2], 74 | text=words[count:], 75 | name='input words', 76 | textposition="top center", 77 | textfont_size=20, 78 | mode='markers+text', 79 | marker={ 80 | 'size': 10, 81 | 'opacity': 1, 82 | 'color': 'black' 83 | } 84 | ) 85 | 86 | data.append(trace_input) 87 | 88 | # Configure the layout 89 | layout = go.Layout( 90 | margin={'l': 0, 'r': 0, 'b': 0, 't': 0}, 91 | showlegend=True, 92 | legend=dict( 93 | x=1, 94 | y=0.5, 95 | font=dict( 96 | family="Courier New", 97 | size=25, 98 | color="black" 99 | )), 100 | font=dict( 101 | family=" Courier New ", 102 | size=15), 103 | autosize=False, 104 | width=1000, 105 | height=1000 106 | ) 107 | 108 | plot_figure = go.Figure(data=data, layout=layout) 109 | plot_figure.show() 110 | 111 | 112 | def main(): 113 | if len(sys.argv) == 1: 114 | print('Insert at least a password.') 115 | sys.exit(-1) 116 | input_passwords = sys.argv[1:] 117 | result = [] 118 | 119 | small_model = compress_fasttext.models.CompressedFastTextKeyedVectors.load('no_w2kp_compressed_model_minngram=2') 120 | 121 | # For each input password, find the 5 most similar ones using small_model embeddings 122 | for password in input_passwords: 123 | sim_passwords = small_model.most_similar(password, topn=5) 124 | sim_passwords = append_list(sim_passwords, password) 125 | print(sim_passwords) 126 | result.extend(sim_passwords) 127 | 128 | similar_password = [password[0] for password in result] 129 | similarity = [password[1] for password in result] 130 | similar_password.extend(input_passwords) 131 | labels = [password[2] for password in result] 132 | label_dict = dict([(y, x + 1) for x, y in enumerate(set(labels))]) 133 | color_map = [label_dict[x] for x in labels] 134 | 135 | display_tsne_scatterplot_3D(small_model, input_passwords, similar_password, labels, color_map, 5, 500, 10000) 136 | 137 | 138 | if __name__ == "__main__": 139 | main() 140 | -------------------------------------------------------------------------------- /w2kp_PRGraph.py: -------------------------------------------------------------------------------- 1 | # Word2Keypress version 2 | import itertools 3 | import sys 4 | import csv 5 | import time 6 | import gensim 7 | import numpy as np 8 | from matplotlib import pyplot as plt 9 | from collections import OrderedDict 10 | from nltk import edit_distance 11 | 12 | from word2keypress import Keyboard 13 | kb = Keyboard() 14 | 15 | 16 | def leet_code(string: str): 17 | for char in string: 18 | if char == 'a': 19 | string = string.replace('a', '4') 20 | elif char == 'b': 21 | string = string.replace('b', '8') 22 | elif char == 'e': 23 | string = string.replace('e', '3') 24 | elif char == 'l': 25 | string = string.replace('l', '1') 26 | elif char == 'o': 27 | string = string.replace('o', '0') 28 | elif char == 's': 29 | string = string.replace('s', '5') 30 | elif char == 't': 31 | string = string.replace('t', '7') 32 | else: 33 | pass 34 | return string 35 | 36 | 37 | # HEURISTICS 38 | def heuristics(pwd1: str, pwd2: str): 39 | if leet_code(pwd1) == leet_code(pwd2): 40 | return True 41 | if pwd1.lower() == pwd2.lower(): 42 | return True 43 | if edit_distance(pwd1, pwd2, transpositions=True) < 5: 44 | return True 45 | return False 46 | 47 | 48 | def main(): 49 | # Usage: 50 | # python3 PRGraph.py 51 | if len(sys.argv) != 3: 52 | sys.exit("Usage: python3 PRGraph.py ") 53 | filename = sys.argv[1] 54 | big_model_file = sys.argv[2] 55 | big_model = gensim.models.fasttext.load_facebook_vectors(big_model_file) 56 | pos_neg_count = OrderedDict() 57 | prec_dict = OrderedDict() 58 | rec_dict = OrderedDict() 59 | 60 | for th in np.arange(0.0, 1.1, 0.1): 61 | pos_neg_count_th = {'TP': 0, 'FP': 0, 'FN': 0} 62 | pos_neg_count[th] = pos_neg_count_th 63 | 64 | with open(filename) as file: 65 | csv_reader = csv.reader(file, delimiter=':') 66 | start_time = time.time() 67 | for i, (user, pass_keyseq_list) in enumerate(csv_reader): 68 | if i % 10000 == 0: 69 | end_time = time.time() 70 | print("Processed {} lines in {} seconds.".format(i, end_time - start_time)) 71 | start_time = end_time 72 | user_pass_list = eval(pass_keyseq_list) 73 | for pwd1, pwd2 in itertools.combinations(user_pass_list, 2): 74 | ground_truth = heuristics(pwd1, pwd2) 75 | # Find similarity percentage using the model 76 | # NB Passwords must be converted in key-presses, because the model was trained with word2keypress dataset. 77 | pwd1_kp, pwd2_kp = kb.print_keyseq(kb.word_to_keyseq(pwd1)), kb.print_keyseq(kb.word_to_keyseq(pwd2)) 78 | sim_score = big_model.similarity(pwd1_kp, pwd2_kp) 79 | 80 | for th, pos_neg_count_th in pos_neg_count.items(): 81 | bin_sim_score = sim_score > th 82 | if bin_sim_score and ground_truth: 83 | pos_neg_count_th['TP'] += 1 84 | elif bin_sim_score and not ground_truth: 85 | pos_neg_count_th['FP'] += 1 86 | elif not bin_sim_score and ground_truth: 87 | pos_neg_count_th['FN'] += 1 88 | 89 | for th, pos_neg_count_th in pos_neg_count.items(): 90 | th_prec = pos_neg_count_th['TP'] / (pos_neg_count_th['TP'] + pos_neg_count_th['FP']) 91 | th_rec = pos_neg_count_th['TP'] / (pos_neg_count_th['TP'] + pos_neg_count_th['FN']) 92 | prec_dict[th] = th_prec 93 | rec_dict[th] = th_rec 94 | 95 | x, y_p = zip(*prec_dict.items()) 96 | _, y_r = zip(*rec_dict.items()) 97 | 98 | plt.plot(x, y_p, label='Precision') 99 | plt.plot(x, y_r, label='Recall') 100 | plt.legend() 101 | plt.grid() 102 | plt.xticks(np.arange(0.0, 1.1, 0.1)) 103 | plt.yticks(np.arange(0.0, 1.05, 0.05)) 104 | plt.savefig("big_model.png") 105 | 106 | 107 | if __name__ == '__main__': 108 | main() 109 | 110 | --------------------------------------------------------------------------------