menu
  • Module trufflehog3.helper

    Helper functions.

Functions
            
                

                def colored(s: str, color: str = '\x1b[32m')
                 ‑> str
            
            
    
    
        
            open_in_new
        
    

        

Return ANSI-colored string.

            
                

                def logger(level: int = 40, name='secret')
                 ‑> logging.Logger
            
            
    
    
        
            open_in_new
        
    

        

Initialize and return named logger singleton.

Note

Level is not changed upon subsequent calls. Use log.setLevel().

Examples

>>> log1 = logger(level=logging.DEBUG, name="debug")
>>> log2 = logger(level=logging.ERROR, name="debug")
>>> log3 = logger(level=logging.ERROR, name="error")
>>> log1 == log2
True
>>> log2.level  # log2 still has DEBUG level
10
>>> log1 == log3
False
>>> log2.setLevel(logging.ERROR)  # log1 and log2 now have ERROR level
>>> log2.level
40
            
                

                def get_lines(s: str, line: int, context: int = 0)
                 ‑> Dict[int, str]
            
            
    
    
        
            open_in_new
        
    

        

Extract lines with context from the given string.

Return dict with lines range and the extracted lines.

Note

It is supposed that line parameter is 1-indexed.

Examples

Basic usage examples

>>> s = "1\n2\n3\n4\n5"
>>> get_lines(s, 3)
{'3': '3'}
>>> get_lines(s, 1, 2)
{'1': '1', '2': '2', '3': '3'}
>>> get_lines(s, 5, 2)
{'3': '3', '4': '4', '5': '5'}
>>> get_lines(s, 3, 10)
{'1': '1', '2': '2', '3': '3', '4': '4', '5': '5'}
            
                

                def get_strings(s: str, alphabet: str, minlen: int)
                 ‑> List[str]
            
            
    
    
        
            open_in_new
        
    

        

Extract substrings of given alphabet from the string.

Examples

Basic usage examples

>>> get_strings("testing get_strings", "abcdefghijklmnopqrstuvwxyz", 5)
['testing', 'strings']
>>> get_strings("something about deadbeef", "0123456789abcdef", 5)
['deadbeef']
            
                

                def shannon_entropy(s: str, alphabet: str)
                 ‑> float
            
            
    
    
        
            open_in_new
        
    

        

Calculate Shannon entropy for given string of alphabet characters.

Note

Return zero for empty string.

Examples

Basic usage examples

>>> shannon_entropy("", "abcdefghijklmnopqrstuvwxyz")
0.0
>>> shannon_entropy("abcd", "abcdefghijklmnopqrstuvwxyz")
2.0
>>> shannon_entropy("1234abcd", "0123456789abcdef")
3.0
Classes
                    
                        class Color
                    
                    
    
    
        
            open_in_new
        
    

                

Supported ANSI colors.

Class variables
var BLACK
var RED
var GREEN
var YELLOW
var BLUE
var MAGENTA
var CYAN
var WHITE
var GRAY
var RESET
var BOLD
var UNDERLINE