Search code examples
pythonencryptionvimblowfish

How to use Python to decrypt files encrypted using Vim's cryptmethod=blowfish2?


I would like to use Python to decrypt files encrypted using Vim encrypted with the cryptmethod=blowfish2 method. I have not seen the encryption method documented anywhere and would appreciate help in figuring out how to do this.

Is this a standard ability with Python, or has a library been implemented, or other?


Solution

  • Check out this module: https://github.com/nlitsme/vimdecrypt. You can use it to decrypt your files, or study the code to learn how to implement it yourself. Example usage:

    from collections import namedtuple
    from vimdecrypt import decryptfile
    
    args = namedtuple('Args', ('verbose', 'test'))(False, False)
    password = 'password'
    with open('somefile', 'rb') as somefile:
        decrypted = decryptfile(somefile.read(), password, args)