forked from primihub/primihub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f782f5
commit 06b253e
Showing
17 changed files
with
373 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from primihub.utils.logger_util import logger | ||
from primihub.MPC.psi import TwoPartyPsi, PsiType, DataType | ||
import random | ||
import time | ||
|
||
class Example: | ||
def run(self): | ||
psi_executor = TwoPartyPsi() | ||
data_len = 10 | ||
#input_data = [str(i) for i in range(data_len)] | ||
input_data = [i for i in range(data_len)] | ||
# input_data = [f"中国{i}" for i in range(data_len)] | ||
input_data_str = [str(i) for i in range(data_len)] | ||
for i in range(1): | ||
result = psi_executor.run(input_data, | ||
["Alice", "Bob"], "Alice", True, | ||
PsiType.ECDH, data_type = DataType.Interger) | ||
logger.info(f"xxxxxxxxxxx loop: {i} psi int result: {result}") | ||
result = psi_executor.run(input_data, | ||
["Alice", "Bob"], "Alice", True, | ||
PsiType.KKRT, data_type = DataType.Interger) | ||
logger.info(f"xxxxxxxxxxx loop: {i} psi int result: {result}") | ||
result = psi_executor.run(input_data_str, | ||
["Alice", "Bob"], "Alice", True, PsiType.ECDH) | ||
logger.info(f"xxxxxxxxxxx loop: {i} psi string result: {result}") | ||
result = psi_executor.run(input_data_str, | ||
["Alice", "Bob"], "Alice", True, PsiType.KKRT) | ||
logger.info(f"xxxxxxxxxxx loop: {i} psi string result: {result}") | ||
|
||
|
||
example = Example() | ||
example.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"task_name": "psi_task", | ||
"task_lang": "python", | ||
"task_code": { | ||
"code_file_path": "example/code/psi_example.py", | ||
"code": "" | ||
}, | ||
"params": { | ||
"auxiliary_server": { | ||
"type": "OBJECT", | ||
"value": { | ||
"is_dataset": true, | ||
"dataset_id": "FAKE_DATA_PARTY_2" | ||
} | ||
} | ||
}, | ||
"component_params": { | ||
"roles": { | ||
"executor": ["Alice", "Bob"] | ||
}, | ||
"common_params": { | ||
"model": "PythonEngine" | ||
}, | ||
"role_params": { | ||
"Alice": { | ||
"data_set": "FAKE_DATA_PARTY_0" | ||
}, | ||
"Bob": { | ||
"data_set": "FAKE_DATA_PARTY_1" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
* Copyright (c) 2023 by PrimiHub | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/ | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
""" | ||
import ph_secure_lib as ph_slib | ||
from primihub.context import Context | ||
from enum import Enum | ||
import numpy as np | ||
from primihub.utils.logger_util import logger | ||
|
||
class PsiType(Enum): | ||
KKRT = "KKRT" | ||
ECDH = "ECDH" | ||
|
||
class DataType(Enum): | ||
Interger = 0 | ||
String = 1 | ||
|
||
class TwoPartyPsi: | ||
def __init__(self): | ||
self.psi_executor = ph_slib.PSIExecutor(Context.message) | ||
|
||
def run(self, | ||
input: np.ndarray, | ||
parties: list, | ||
receiver: str, | ||
broadcast: bool, | ||
protocol: PsiType = PsiType.KKRT, | ||
data_type: DataType = DataType.String): | ||
if len(input) == 0: | ||
return list() | ||
if data_type == DataType.Interger: | ||
logger.info(f"dtype is int") | ||
return self.psi_executor.run_as_integer( | ||
input, parties, receiver, broadcast, protocol.value) | ||
elif data_type == DataType.String: | ||
logger.info(f"dtype is str") | ||
return self.psi_executor.run_as_string( | ||
input, parties, receiver, broadcast, protocol.value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.