refactored and partially tested file encryption