码迷,mamicode.com
首页 > 移动开发 > 详细

PDF目录标签自动生成示范 《Handbook.of.Applied.Cryptography》(Alfred.J..Menezes).pdf

时间:2015-08-07 20:09:43      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:


利用JavaScript自动生PDF书签目录 



使用软件版本 Acrobat XI


大多数的扫描版PDF电子图书都可以在官网或者各大网上书店找到目录,很多都是带有页码的。 通过脚本可以将目录自动转化为书签,添加到PDF中。


把目录数据复制粘贴到一个文本文件中,确保每一行都是一条书签,然后合并成一行内容,并将所有换行符用 "\n" 字符替换作为 JavaScript 的转义字符,放入 Bookmark.js 的 data 变量中。


然后把Bookmark.js文件保存到Acrobat安装目录下的JavaScript文件夹里面,并保存 js 为UTF-8的编码。默认位置是:
Adobe\Acrobat 11.0\Acrobat\Javascripts


以 Handbook of Apply Cryptography 这本书的电子版本为例,目录和所有共享章节都可以到网站上下载:
http://cacr.uwaterloo.ca/hac/index.html


此教材目录标签已经处理好上传致下载中心,搜索下载却可,也可以用它做测试用。

Handbook.of.Applied.Cryptography(Alfred.J..Menezes).pdf 

操作过程


将 toc3.pdf 的目录内容整理成以下的形式,确保页码数值后没有空格等等,使用 Editplus 的编辑菜单的格式化工具,可以清除行尾的空格:
    1 Overview of Cryptography 1 
    1.1 Introduction 1 
    1.2 Information security and cryptography 2
    ……
然后使用 Editplus 这种带有正则替换功能的编辑器,在查找内容和替换内容分别设置为 \n 和 \\n,打开正则功能,将所有换行符替换成 "\n",结果像以下这样。
    1 Overview of Cryptography 1 \n1.1 Introduction 1 \n1.2 Information security and cryptography 2 \n


再将这些数据放到 Bookmark.js 的 data 变量中就可以使用了。

完整代码 bookmarks.js:

app.addMenuItem({    
    cName: "JIMBO:GENERATE",
    cUser: "书签自动生成(&B)",
    cParent: "Edit",
    cExec: "bookm();",
    cEnable: "event.rc= (event.target != null);"
});

var rex = /^(.+?)(\d+)$/;
var rel = /\./g;

var bm = {
    title : "Handbook of Applied Cryptography",
    data : "1 Overview of Cryptography 1\n1.1 Introduction 1\n1.2 Information security and cryptography 2\n1.3 Background on functions 6\n1.3.1 Functions (1-1, one-way, trapdoor one-way) 6\n1.3.2 Permutations 10\n1.3.3 Involutions 10\n1.4 Basic terminology and concepts 11\n1.5 Symmetric-key encryption 15\n1.5.1 Overview of block ciphers and stream ciphers 15\n1.5.2 Substitution ciphers and transposition ciphers 17\n1.5.3 Composition of ciphers 19\n1.5.4 Stream ciphers 20\n1.5.5 The key space 21\n1.6 Digital signatures 22\n1.7 Authentication and identi.cation 24\n1.7.1 Identi.cation 24\n1.7.2 Data origin authentication 25\n1.8 Public-key cryptography 25\n1.8.1 Public-key encryption 25\n1.8.2 The necessity of authentication in public-key systems 27\n1.8.3 Digital signatures from reversible public-key encryption 28\n1.8.4 Symmetric-key vs. public-key cryptography 31\n1.9 Hash functions 33\n1.10 Protocols and mechanisms 33\n1.11 Key establishment, management, and certi.cation 35\n1.11.1 Key management through symmetric-key techniques 36\n1.11.2 Key management through public-key techniques 37\n1.11.3 Trusted third parties and public-key certi.cates 39\n1.12 Pseudorandom numbers and sequences 39\n1.13 Classes of attacks and security models 41\n1.13.1 Attacks on encryption schemes 41\n1.13.2 Attacks on protocols 42\n1.13.3 Models for evaluating security 42\n1.13.4 Perspective for computational security 44\n1.14 Notes and further references 45\n2 Mathematical Background 49\n2.1 Probability theory 50\n2.1.1 Basic definitions 50\n2.1.2 Conditional probability 51\n2.1.3 Random variables 51\n2.1.4 Binomial distribution 52\n2.1.5 Birthday attacks 53\n2.1.6 Random mappings 54\n2.2 Information theory 56\n2.2.1 Entropy 56\n2.2.2 Mutual information 57\n2.3 Complexity theory 57\n2.3.1 Basic definitions 57\n2.3.2 Asymptotic notation 58\n2.3.3 Complexity classes 59\n2.3.4 Randomized algorithms 62\n2.4 Number theory 63\n2.4.1 The integers 63\n2.4.2 Algorithms in Z66\n2.4.3 The integers modulo n 67\n2.4.4 Algorithms in Zn71\n2.4.5 The Legendre and Jacobi symbols 72\n2.4.6 Blum integers 74\n2.5 Abstract algebra 75\n2.5.1 Groups 75\n2.5.2 Rings 76\n2.5.3 Fields 77\n2.5.4 Polynomial rings 78\n2.5.5 Vector spaces 79\n2.6 Finite fields 80\n2.6.1 Basic properties 80\n2.6.2 The Euclidean algorithm for polynomials 81\n2.6.3 Arithmetic of polynomials 83\n2.7 Notes and further references 85\n3 Number-Theoretic Reference Problems 87\n3.1 Introduction and overview 87\n3.2 The integer factorization problem 89\n3.2.1 Trial division 90\n3.2.2 Pollard's rho factoring algorithm 91\n3.2.3 Pollard's p-1 factoring algorithm 92\n3.2.4 Elliptic curve factoring 94\n3.2.5 Random square factoring methods 94\n3.2.6 Quadratic sieve factoring 95\n3.2.7 Number field sieve factoring 98\n3.3 The RSA problem 98\n3.4 The quadratic residuosity problem 99\n3.5 Computing square roots inZn99\n3.5.1 Case (i)  nprime 100\n3.5.2 Case (ii)  composite 101\n3.6 The discrete logarithm problem 103\n3.6.1 Exhaustive search 104\n3.6.2 Baby-step giant-step algorithm 104\n3.6.3 Pollard's rho algorithm for logarithms 106\n3.6.4 Pohlig-Hellman algorithm 107\n3.6.5 Index-calculus algorithm 109\n3.6.6 Discrete logarithm problem in subgroups of 113\n3.7 The Diffie-Hellman problem 113\n3.8 Composite moduli 114\n3.9 Computing individual bits 114\n3.9.1 The discrete logarithm problem in - individual bits 116\n3.9.2 The RSA problem - individual bits 116\n3.9.3 The Rabin problem - individual bits 117\n3.10 The subset sum problem 117\n3.10.1 The -lattice basis reduction algorithm 118\n3.10.2 Solving subset sum problems of low density 120\n3.10.3 Simultaneous diophantine approximation 121\n3.11 Factoring polynomials over .nite .elds 122\n3.11.1 Square-free factorization 123\n3.11.2 Berlekamp's -matrix algorithm 124\n3.12 Notes and further references 125\n4 Public-Key Parameters 133\n4.1 Introduction 133\n4.1.1 Generating large prime numbers naively 134\n4.1.2 Distribution of prime numbers 134\n4.2 Probabilistic primality tests 135\n4.2.1 Fermat's test 136\n4.2.2 Solovay-Strassen test 137\n4.2.3 Miller-Rabin test 138\n4.2.4 Comparison  Fermat, Solovay-Strassen, and Miller-Rabin 140\n4.3 (True) Primality tests 142\n4.3.1 Testing Mersenne numbers 142\n4.3.2 Primality testing using the factorization of 143\n4.3.3 Jacobi sum test 144\n4.3.4 Tests using elliptic curves 145\n4.4 Prime number generation 145\n4.4.1 Random search for probable primes 145\n4.4.2 Strong primes 149\n4.4.3 NIST method for generating DSA primes 150\n4.4.4 Constructive techniques for provable primes 152\n4.5 Irreducible polynomials over 154\n4.5.1 Irreducible polynomials 154\n4.5.2 Irreducible trinomials 157\n4.5.3 Primitive polynomials 157\n4.6 Generators and elements of high order 160\n4.6.1 Selecting a prime and generator of 164\n4.7 Notes and further references 165\n5 Pseudorandom Bits and Sequences 169\n5.1 Introduction 169\n5.1.1 Background and Classi.cation 170\n5.2 Random bit generation 171\n5.3 Pseudorandom bit generation 173\n5.3.1 ANSI X9.17 generator 173\n5.3.2 FIPS 186 generator 174\n5.4 Statistical tests 175\n5.4.1 The normal and chi-square distributions 176\n5.4.2 Hypothesis testing 179\n5.4.3 Golomb's randomness postulates 180\n5.4.4 Five basic tests 181\n5.4.5 Maurer's universal statistical test 183\n5.5 Cryptographically secure pseudorandom bit generation 185\n5.5.1 RSA pseudorandom bit generator 185\n5.5.2 Blum-Blum-Shub pseudorandom bit generator 186\n5.6 Notes and further references 187\n6 Stream Ciphers 191\n6.1 Introduction 191\n6.1.1 Classi.cation 192\n6.2 Feedback shift registers 195\n6.2.1 Linear feedback shift registers 195\n6.2.2 Linear complexity 198\n6.2.3 Berlekamp-Massey algorithm 200\n6.2.4 Nonlinear feedback shift registers 202\n6.3 Stream ciphers based on LFSRs 203\n6.3.1 Nonlinear combination generators 205\n6.3.2 Nonlinear .lter generators 208\n6.3.3 Clock-controlled generators 209\n6.4 Other stream ciphers 212\n6.4.1 SEAL 213\n6.5 Notes and further references 216\n7 Block Ciphers 223\n7.1 Introduction and overview 223\n7.2 Background and general concepts 224\n7.2.1 Introduction to block ciphers 224\n7.2.2 Modes of operation 228\n7.2.3 Exhaustive key search and multiple encryption 233\n7.3 Classical ciphers and historical development 237\n7.3.1 Transposition ciphers (background) 238\n7.3.2 Substitution ciphers (background) 238\n7.3.3 Polyalphabetic substitutions and Vigen`ere ciphers (historical) 241\n7.3.4 Polyalphabetic cipher machines and rotors (historical) 242\n7.3.5 Cryptanalysis of classical ciphers (historical) 245\n7.4 DES 250\n7.4.1 Product ciphers and Feistel ciphers 250\n7.4.2 DES algorithm 252\n7.4.3 DES properties and strength 256\n7.5 FEAL 259\n7.6 IDEA 263\n7.7 SAFER, RC5, and other block ciphers 266\n7.7.1 SAFER 266\n7.7.2 RC5 269\n7.7.3 Other block ciphers 270\n7.8 Notes and further references 271\n8 Public-Key Encryption 283\n8.1 Introduction 283\n8.1.1 Basic principles 284\n8.2 RSA public-key encryption 285\n8.2.1 Description 286\n8.2.2 Security of RSA 287\n8.2.3 RSA encryption in practice 290\n8.3 Rabin public-key encryption 292\n8.4 ElGamal public-key encryption 294\n8.4.1 Basic ElGamal encryption 294\n8.4.2 Generalized ElGamal encryption 297\n8.5 McEliece public-key encryption 298\n8.6 Knapsack public-key encryption 300\n8.6.1 Merkle-Hellman knapsack encryption 300\n8.6.2 Chor-Rivest knapsack encryption 302\n8.7 Probabilistic public-key encryption 306\n8.7.1 Goldwasser-Micali probabilistic encryption 307\n8.7.2 Blum-Goldwasser probabilistic encryption 308\n8.7.3 Plaintext-aware encryption 311\n8.8 Notes and further references 312\n9 Hash Functions and Data Integrity 321\n9.1 Introduction 321\n9.2 Classi.cation and framework 322\n9.2.1 General classi.cation 322\n9.2.2 Basic properties and de.nitions 323\n9.2.3 Hash properties required for speci.c applications 327\n9.2.4 One-way functions and compression functions 327\n9.2.5 Relationships between properties 329\n9.2.6 Other hash function properties and applications 330\n9.3 Basic constructions and general results 332\n9.3.1 General model for iterated hash functions 332\n9.3.2 General constructions and extensions 333\n9.3.3 Formatting and initialization details 334\n9.3.4 Security objectives and basic attacks 335\n9.3.5 Bitsizes required for practical security 337\n9.4 Unkeyed hash functions (MDCs) 338\n9.4.1 Hash functions based on block ciphers 338\n9.4.2 Customized hash functions based on MD4 343\n9.4.3 Hash functions based on modular arithmetic 351\n9.5 Keyed hash functions (MACs) 352\n9.5.1 MACs based on block ciphers 353\n9.5.2 Constructing MACs from MDCs 354\n9.5.3 Customized MACs 356\n9.5.4 MACs for stream ciphers 358\n9.6 Data integrity and message authentication 359\n9.6.1 Background and de.nitions 359\n9.6.2 Non-malicious vs. malicious threats to data integrity 362\n9.6.3 Data integrity using a MAC alone 364\n9.6.4 Data integrity using an MDC and an authentic channel 364\n9.6.5 Data integrity combined with encryption 364\n9.7 Advanced attacks on hash functions 368\n9.7.1 Birthday attacks 369\n9.7.2 Pseudo-collisions and compression function attacks 371\n9.7.3 Chaining attacks 373\n9.7.4 Attacks based on properties of underlying cipher 375\n9.8 Notes and further references 376\n10 Identi.cation and Entity Authentication 385\n10.1 Introduction 385\n10.1.1 Identi.cation objectives and applications 386\n10.1.2 Properties of identi.cation protocols 387\n10.2 Passwords (weak authentication) 388\n10.2.1 Fixed password schemes  techniques 389\n10.2.2 Fixed password schemes  attacks 391\n10.2.3 Case study - UNIX passwords 393\n10.2.4 PINs and passkeys 394\n10.2.5 One-time passwords (towards strong authentication) 395\n10.3 Challenge-response identi.cation (strong authentication) 397\n10.3.1 Background on time-variant parameters 397\n10.3.2 Challenge-response by symmetric-key techniques 400\n10.3.3 Challenge-response by public-key techniques 403\n10.4 Customized and zero-knowledge identi.cation protocols 405\n10.4.1 Overview of zero-knowledge concepts 405\n10.4.2 Feige-Fiat-Shamir identi.cation protocol 410\n10.4.3 GQ identi.cation protocol 412\n10.4.4 Schnorr identi.cation protocol 414\n10.4.5 Comparison  Fiat-Shamir, GQ, and Schnorr 416\n10.5 Attacks on identi.cation protocols 417\n10.6 Notes and further references 420\n11 Digital Signatures 425\n11.1 Introduction 425\n11.2 A framework for digital signature mechanisms 426\n11.2.1 Basic de.nitions 426\n11.2.2 Digital signature schemes with appendix 428\n11.2.3 Digital signature schemes with message recovery 430\n11.2.4 Types of attacks on signature schemes 432\n11.3 RSA and related signature schemes 433\n11.3.1 The RSA signature scheme 433\n11.3.2 Possible attacks on RSA signatures 434\n11.3.3 RSA signatures in practice 435\n11.3.4 The Rabin public-key signature scheme 438\n11.3.5 ISO/IEC 9796 formatting 442\n11.3.6 PKCS #1 formatting 445\n11.4 Fiat-Shamir signature schemes 447\n11.4.1 Feige-Fiat-Shamir signature scheme 447\n11.4.2 GQ signature scheme 450\n11.5 The DSA and related signature schemes 451\n11.5.1 The Digital Signature Algorithm (DSA) 452\n11.5.2 The ElGamal signature scheme 454\n11.5.3 The Schnorr signature scheme 459\n11.5.4 The ElGamal signature scheme with message recovery 460\n11.6 One-time digital signatures 462\n11.6.1 The Rabin one-time signature scheme 462\n11.6.2 The Merkle one-time signature scheme 464\n11.6.3 Authentication trees and one-time signatures 466\n11.6.4 The GMR one-time signature scheme 468\n11.7 Other signature schemes 471\n11.7.1 Arbitrated digital signatures 472\n11.7.2 ESIGN 473\n11.8 Signatures with additional functionality 474\n11.8.1 Blind signature schemes 475\n11.8.2 Undeniable signature schemes 476\n11.8.3 Fail-stop signature schemes 478\n11.9 Notes and further references 481\n12 Key Establishment Protocols 489\n12.1 Introduction 489\n12.10 Notes and further references 534\n12.2 Classi.cation and framework 490\n12.2.1 General classi.cation and fundamental concepts 490\n12.2.2 Objectives and properties 493\n12.2.3 Assumptions and adversaries in key establishment protocols 495\n12.3 Key transport based on symmetric encryption 497\n12.3.1 Symmetric key transport and derivation without a server 497\n12.3.2 Kerberos and related server-based protocols 500\n12.4 Key agreement based on symmetric techniques 505\n12.5 Key transport based on public-key encryption 506\n12.5.1 Key transport using PK encryption without signatures 507\n12.5.2 Protocols combining PK encryption and signatures 509\n12.5.3 Hybrid key transport protocols using PK encryption 512\n12.6 Key agreement based on asymmetric techniques 515\n12.6.1 Dif.e-Hellman and related key agreement protocols 515\n12.6.2 Implicitly-certi.ed public keys 520\n12.6.3 Dif.e-Hellman protocols using implicitly-certi.ed keys 522\n12.7 Secret sharing 524\n12.7.1 Simple shared control schemes 524\n12.7.2 Threshold schemes 525\n12.7.3 Generalized secret sharing 526\n12.8 Conference keying 528\n12.9 Analysis of key establishment protocols 530\n12.9.1 Attack strategies and classic protocol .aws 530\n12.9.2 Analysis objectives and methods 532\n13 Key Management Techniques 543\n13.1 Introduction 543\n13.2 Background and basic concepts 544\n13.2.1 Classifying keys by algorithm type and intended use 544\n13.2.2 Key management objectives, threats, and policy 545\n13.2.3 Simple key establishment models 546\n13.2.4 Roles of third parties 547\n13.2.5 Tradeoffs among key establishment protocols 550\n13.3 Techniques for distributing con.dential keys 551\n13.3.1 Key layering and cryptoperiods 551\n13.3.2 Key translation centers and symmetric-key certi.cates 553\n13.4 Techniques for distributing public keys 555\n13.4.1 Authentication trees 556\n13.4.2 Public-key certi.cates 559\n13.4.3 Identity-based systems 561\n13.4.4 Implicitly-certi.ed public keys 562\n13.4.5 Comparison of techniques for distributing public keys 563\n13.5 Techniques for controlling key usage 567\n13.5.1 Key separation and constraints on key usage 567\n13.5.2 Techniques for controlling use of symmetric keys 568\n13.6 Key management involving multiple domains 570\n13.6.1 Trust between two domains 570\n13.6.2 Trust models involving multiple certi.cation authorities 572\n13.6.3 Certi.cate distribution and revocation 576\n13.7 Key life cycle issues 577\n13.7.1 Lifetime protection requirements 578\n13.7.2 Key management life cycle 578\n13.8 Advanced trusted third party services 581\n13.8.1 Trusted timestamping service 581\n13.8.2 Non-repudiation and notarization of digital signatures 582\n13.8.3 Key escrow 584\n13.9 Notes and further references 586\n14 Effcient Implementation 591\n14.1 Introduction 591\n14.2 Multiple-precision integer arithmetic 592\n14.2.1 Radix representation 592\n14.2.2 Addition and subtraction 594\n14.2.3 Multiplication 595\n14.2.4 Squaring 596\n14.2.5 Division 598\n14.3 Multiple-precision modular arithmetic 599\n14.3.1 Classical modular multiplication 600\n14.3.2 Montgomery reduction 600\n14.3.3 Barrett reduction 603\n14.3.4 Reduction methods for moduli of special form 605\n14.4 Greatest common divisor algorithms 606\n14.4.1 Binary gcd algorithm 606\n14.4.2 Lehmer's gcd algorithm 607\n14.4.3 Binary extended gcd algorithm 608\n14.5 Chinese remainder theorem for integers 610\n14.5.1 Residue number systems 611\n14.5.2 Garner's algorithm 612\n14.6 Exponentiation 613\n14.6.1 Techniques for general exponentiation 614\n14.6.2 Fixed-exponent exponentiation algorithms 620\n14.6.3 Fixed-base exponentiation algorithms 623\n14.7 Exponent recoding 627\n14.7.1 Signed-digit representation 627\n14.7.2 String-replacement representation 628\n14.8 Notes and further references 630\n15 Patents and Standards 635\n15.1 Introduction 635\n15.2 Patents on cryptographic techniques 635\n15.2.1 Five fundamental patents 636\n15.2.2 Ten prominent patents 638\n15.2.3 Ten selected patents 641\n15.2.4 Ordering and acquiring patents 645\n15.3 Cryptographic standards 645\n15.3.1 International standards - cryptographic techniques 645\n15.3.2 Banking security standards (ANSI, ISO) 648\n15.3.3 International security architectures and frameworks 653\n15.3.4 U.S. government standards (FIPS) 654\n15.3.5 Internet standards and RFCs 655\n15.3.6 De facto standards 656\n15.3.7 Ordering and acquiring standards 656\n15.4 Notes and further references 657\nA Bibliography of Papers from Selected Cryptographic Forums 663\nA.1 Asiacrypt/Auscrypt Proceedings 663\nA.2 Crypto Proceedings 667\nA.3 Eurocrypt Proceedings 684\nA.4 Fast Software Encryption Proceedings 698\nA.5 Journal of Cryptology papers 700\nReferences 703\nIndex 755\n"
}

function bookm()
{
    if( this.title.indexOf(bm.title) >= 0 ){
        var offset = app.response({    
            cQuestion: "输入书本第一页对应的 Acrobat 页码数字:",
            cTitle: "书签自动生成 by Jimbowhy",    
            cDefault: "1",    
            cLabel: ""
        });
     if(offset==null) return;

        var tokens = bm.data.split("\n")

        // use app thermometer
        var therm = app.thermometer
        therm.duration = 10*tokens.length;
        therm.begin();
        therm.text = "正在生成书签 ... (取消请按: Esc)";

        this.bookmarkRoot.createChild("目录","this.pageNum=0;");
        var root = this.bookmarkRoot.children[0];
        makeBookmarks( root, 1, offset-1-1, tokens, therm);
        therm.end();

    }else{
        app.alert({ 
            cMsg: this.title+",没有发现书本对应的目录数据,请设置 Bookmark.js 的数据,默认位置在:\nAdobe\\Acrobat 11.0\\Acrobat\\Javascripts",
            nIcon: 3,
            cTitle: '书签自动生成'
        }); 
    }

}

function parseContent(data){
    var m = rex.exec(data);
    var l = m[0].split(" ")[0].split(rel).length;
    var prefix = l==1 && parseInt(m[0]);
    return {name: (prefix? "Chapter ":"")+m[1], page:+m[2], level:+l};
}

function makeBookmarks(root, level, offset, list, therm){
    
    if (list.length==0) return;
    
    var item = null;
    while( item = list.shift() ){
        // check if the search is canceled.
        if(app.thermometer.cancel) {
            return null;
        }
        therm.value += 10;
        var len = root.children? root.children.length:0;
        var m = item.name? item:parseContent(item);
        //app.alert(m.name +", " + m.page + ", "+m.level);
        if( level==m.level ) {
            var cExpr = "this.pageNum=[p];".replace("[p]",m.page+offset);
            root.createChild(m.name, cExpr, len);
        }else if( level>m.level ){
            list.unshift(m);
            return;
        }else{
            var sub = root.children[len-1];
            //app.alert(sub.name);
            list.unshift(m);
            makeBookmarks(sub, m.level, offset, list, therm);
        }
    }
}

有必要可以自行修改或添加功能设置。






版权声明:本文为博主原创文章,未经博主允许不得转载。

PDF目录标签自动生成示范 《Handbook.of.Applied.Cryptography》(Alfred.J..Menezes).pdf

标签:

原文地址:http://blog.csdn.net/winsenjiansbomber/article/details/47341155

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!