Repository: blairconrad/dicognito

Issue:
Rename salt to seed
From the outside, it should be billed as a seed for randomness, even though inside `Randomizer`, it's used as a salt when hashing values.

Discussion:

Patch:
diff --git a/src/dicognito/__main__.py b/src/dicognito/__main__.py
index 985de48..e9d01dc 100644
--- a/src/dicognito/__main__.py
+++ b/src/dicognito/__main__.py
@@ -61,10 +61,10 @@ def main(args=None):
         help="Set the log level. May be one of DEBUG, INFO, WARNING, ERROR, or CRITICAL.",
     )
     parser.add_argument(
-        "--salt",  # currently only intended to make testing easier
-        help="The salt to use when generating random attribute values. Primarily "
+        "--seed",  # currently only intended to make testing easier
+        help="The seed to use when generating random attribute values. Primarily "
         "intended to make testing easier. Best anonymization practice is to omit "
-        "this value and let dicognito generate its own random salt.",
+        "this value and let dicognito generate its own random seed.",
     )
     parser.add_argument("--version", action="version", version=dicognito.__version__)
 
@@ -75,7 +75,7 @@ def main(args=None):
         raise ValueError("Invalid log level: %s" % args.log_level)
     logging.basicConfig(format="", level=numeric_level)
 
-    anonymizer = Anonymizer(id_prefix=args.id_prefix, id_suffix=args.id_suffix, salt=args.salt)
+    anonymizer = Anonymizer(id_prefix=args.id_prefix, id_suffix=args.id_suffix, seed=args.seed)
 
     ConvertedStudy = collections.namedtuple("ConvertedStudy", ["AccessionNumber", "PatientID", "PatientName"])
 
diff --git a/src/dicognito/anonymizer.py b/src/dicognito/anonymizer.py
index 5722d98..8fe4912 100644
--- a/src/dicognito/anonymizer.py
+++ b/src/dicognito/anonymizer.py
@@ -39,7 +39,7 @@ class Anonymizer:
     >>>         dataset.save_as("new-" + filename)
     """
 
-    def __init__(self, id_prefix="", id_suffix="", salt=None):
+    def __init__(self, id_prefix="", id_suffix="", seed=None):
         """\
         Create a new Anonymizer.
 
@@ -51,13 +51,13 @@ class Anonymizer:
         id_suffix : str
             A prefix to add to all unstructured ID fields, such as Patient
             ID, Accession Number, etc.
-        salt
+        seed
             Not intended for general use. Seeds the data randomizer in order
             to produce consistent results. Used for testing.
         """
         minimum_offset_hours = 62 * 24
         maximum_offset_hours = 730 * 24
-        randomizer = Randomizer(salt)
+        randomizer = Randomizer(seed)
         address_anonymizer = AddressAnonymizer(randomizer)
         self._element_handlers = [
             UnwantedElementsStripper(
diff --git a/src/dicognito/randomizer.py b/src/dicognito/randomizer.py
index 589df27..cbcf4c9 100644
--- a/src/dicognito/randomizer.py
+++ b/src/dicognito/randomizer.py
@@ -3,20 +3,20 @@ import os
 
 
 class Randomizer:
-    def __init__(self, salt):
+    def __init__(self, seed):
         """\
         Create a new Randomizer.
 
         Parameters
         ----------
-        salt
+        seed
             Not intended for general use. Seeds the data randomizer so it
             produces consistent results when anonymizing elements with the
             same initial values.
         """
-        if salt is None:
-            salt = os.urandom(20)
-        self.salt = str(salt)
+        if seed is None:
+            seed = os.urandom(20)
+        self.seed = str(seed)
 
     def to_int(self, original_value):
         """\
@@ -28,7 +28,7 @@ class Randomizer:
         original_value
             The original value that will ultimately be replaced.
         """
-        message = self.salt + str(original_value)
+        message = self.seed + str(original_value)
         if isinstance(message, bytes):
             encoded = message
             hash = [ord(d) for d in hashlib.md5(encoded).digest()]
diff --git a/src/dicognito/release_notes.md b/src/dicognito/release_notes.md
index 9f3a779..56c75b1 100644
--- a/src/dicognito/release_notes.md
+++ b/src/dicognito/release_notes.md
@@ -1,3 +1,7 @@
+### Changed
+
+- Renamed "salt" to "seed" in command-line tool and `Anonymizer` class ([#49](https://github.com/blairconrad/dicognito/issues/49))
+
 ### New
 
 - Provide `--version` flag and `__version__` attribute ([#47](https://github.com/blairconrad/dicognito/issues/47))


Test patch:
diff --git a/tests/test_commandline.py b/tests/test_commandline.py
index 24dc9ba..91933a8 100644
--- a/tests/test_commandline.py
+++ b/tests/test_commandline.py
@@ -41,9 +41,9 @@ def test_summary_mixed_files_reports_on_each_study(capsys):
     expected_output = """\
 Accession Number Patient ID       Patient Name
 ---------------- ----------       ------------
-DRVN05NEDUYD     2S183ZNON7HU     RICHMOND^MARCY^NITA
-8NZGNEJWE7QA     NPC1XHSJT51Z     MORROW^SUSANNA^LUCIEN
-SXJXM4HE90EO     NPC1XHSJT51Z     MORROW^SUSANNA^LUCIEN
+HGED6DXQTO1F     DQFZ0HDKPYUX     JENSEN^KELLIE^PATRICK
+XV266HDCGIOH     DQFZ0HDKPYUX     JENSEN^KELLIE^PATRICK
+UUM68P1IJHBE     LXO0DMOPN7PV     BUCHANAN^ALBA^MADGE
 """
     run_dicognito(path_to("p*"))
     (actual_output, actual_error) = capsys.readouterr()
@@ -125,7 +125,7 @@ def path_to(end_of_path):
 
 
 def run_dicognito(*extra_args):
-    dicognito.__main__.main(("--salt", "salt for test") + extra_args)
+    dicognito.__main__.main(("--seed", "") + extra_args)
 
 
 def read_file(*directory_parts):