Commit 1369d029 authored by Hoang Gia NGUYEN's avatar Hoang Gia NGUYEN
Browse files

testing

parent d4e94487

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.
#encrypt
licenseNo=$1
# ex: "23 65 78 127 255" (en ASCII)
filename=$2
# ex: "l" (extension will be .ct)
outputDir=$3
# ex: lcheck/
sample=$4
# ex: 40
keyDir=$5
# ex: keys/
CURR_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# time ./ANN_encrypt_v1 "$licenseNo" "$filename" "$outputDir" "$sample" "$keyDir"
time ${CURR_DIR}/ANN_encrypt_v1 "$licenseNo" "$filename" "$outputDir" "$sample" "$keyDir"
\ No newline at end of file
# evaluate
licensePath=$1
# ex: lcheck/l.ct
licensePathList=${@: 2:$#-5}
# licensePathList="${@:2:102}"
# for var in "${@: 2:$#-7}"
# do
# echo "$var"
# done
# ex: parent/l0/l.ct parent/l1/l.ct parent/l2/l.ct parent/l3/l.ct parent/l4/l.ct parent/l5/l.ct parent/l6/l.ct parent/l7/l.ct parent/l8/l.ct parent/l9/l.ct
filename=${@: -4:1}
# ex: "l" (extension will be .ct)
outputDir=${@: -3:1}
# ex: result/
sample=${@: -2:1}
# ex: 40
KeyDir=${@: -1}
# ex: keys/
# linkingKeyPath=${@: -3:1}
# # ex: ckks.lk
# galoisKeyPath=${@: -2:1}
# # ex: ckks.gk
# publicKeyPath=${@: -1}
# # ex: ckks.pk
CURR_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# time ./ANN_evaluate_v1 "$licensePath" $licensePathList "$filename" "$outputDir" "$sample" "$linkingKeyPath" "$galoisKeyPath" "$publicKeyPath"
# time ./ANN_evaluate_v1 "$licensePath" $licensePathList "$filename" "$outputDir" "$sample" "$KeyDir"
time ${CURR_DIR}/ANN_evaluate_v1 "$licensePath" $licensePathList "$filename" "$outputDir" "$sample" "$KeyDir"
\ No newline at end of file
#gen key
keyDir=$1
# ex: keys/
CURR_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# time ./ANN_genkey_v1 "$keyDir"
time ${CURR_DIR}/ANN_genkey_v1 "$keyDir"
\ No newline at end of file
243 65 191 66 134 2 36 209 39 215 143 95 22 211 213 168 142 178 25 77 88 120 159 33 247 144 244 253 14 39 205 86 123 249 215 166 113 82 205 150
175 50 195 231 96 99 136 186 176 104 92 99 13 0 110 219 168 146 101 169 70 189 249 6 205 90 118 46 166 136 3 243 158 95 230 38 149 234 81 68
175 223 168 200 187 205 246 220 192 127 220 10 38 6 241 89 77 25 53 169 12 91 49 133 75 89 118 147 211 16 18 90 159 50 175 114 249 103 145 153
49 38 145 31 236 196 166 137 78 10 134 2 9 48 43 202 166 45 141 90 71 90 3 252 26 204 222 82 120 151 253 232 223 158 248 92 76 218 17 20
253 197 52 226 110 61 176 101 59 117 111 242 135 173 213 205 211 108 89 132 49 113 195 86 63 122 64 184 137 144 183 174 195 112 166 50 32 10 55 61
174 82 23 246 3 4 64 68 96 49 0 64 111 225 149 57 79 42 33 154 9 38 130 10 151 121 104 222 138 228 248 83 145 192 106 30 126 198 248 76
180 247 84 38 133 245 173 82 166 53 211 109 137 8 48 191 137 233 238 3 6 252 162 232 253 125 29 210 241 208 9 1 160 232 209 215 203 250 19 95
224 122 90 44 22 59 96 241 96 5 186 23 249 4 201 102 23 99 38 242 38 11 99 253 184 38 146 248 198 74 214 21 114 63 242 42 100 142 50 9
27 95 228 0 180 66 2 225 77 120 56 85 176 254 198 157 229 112 97 253 181 26 235 172 93 123 154 100 112 157 17 231 249 250 168 61 185 10 23 223
93 79 52 151 155 73 110 9 111 93 241 249 109 94 46 181 223 180 146 145 180 220 10 88 208 243 229 116 55 68 219 252 230 119 188 235 75 213 186 49
113 68 160 136 24 127 12 242 95 245 251 193 159 128 167 209 169 141 59 75 148 209 46 147 127 11 96 49 101 36 27 168 159 70 133 223 190 41 62 111
204 224 117 188 183 127 35 194 202 71 227 252 187 199 93 187 45 6 13 26 160 189 74 4 42 41 220 73 14 149 232 126 38 240 250 32 154 10 86 117
50 177 30 212 186 247 71 41 17 66 116 129 97 126 206 97 211 146 215 132 166 164 159 196 179 219 118 9 223 202 9 36 165 18 103 127 127 86 141 7
100 132 232 248 220 67 101 79 90 171 184 246 27 161 186 73 60 207 87 41 90 216 92 128 37 168 132 223 226 77 122 237 189 84 167 2 177 29 190 34
125 249 230 63 58 47 50 166 229 202 116 158 178 187 13 206 170 66 68 247 225 96 191 118 244 173 231 73 104 151 81 94 129 186 112 2 177 16 25 176
3 110 136 235 79 87 181 238 1 10 63 76 249 75 138 219 113 139 120 142 22 14 15 10 106 41 20 88 214 10 222 249 64 154 201 65 155 15 64 126
122 208 157 182 115 121 122 45 23 70 77 10 118 119 196 193 133 76 171 235 237 84 161 69 250 250 87 180 132 227 173 58 224 173 76 127 61 216 180 42
160 8 76 36 240 227 62 127 191 177 184 122 236 65 168 71 127 41 29 237 240 13 243 13 82 252 189 84 207 17 237 36 148 39 100 79 188 117 226 34
220 170 19 17 240 120 251 108 73 236 13 222 6 151 158 15 114 111 224 137 96 67 227 226 163 183 75 168 169 142 68 168 43 116 110 2 40 48 246 56
129 18 215 139 153 101 0 78 41 84 166 43 124 117 38 143 234 111 196 215 224 227 139 168 121 168 243 190 113 206 242 244 106 238 36 228 232 242 116 23
96 196 168 14 3 243 231 228 157 42 92 68 180 245 158 92 24 220 95 20 242 40 220 203 97 204 117 236 167 197 168 145 194 116 54 83 240 204 224 196
242 120 49 36 230 129 177 52 253 37 64 122 162 25 33 241 144 30 57 243 96 218 181 34 83 111 47 109 12 222 236 60 106 211 151 240 106 90 222 176
188 94 62 191 29 58 226 217 156 180 232 75 128 182 96 135 50 43 237 169 239 132 195 85 110 183 221 218 19 132 178 6 56 170 239 25 173 18 2 177
172 121 70 34 39 58 92 54 221 187 16 209 74 118 106 236 157 67 137 56 63 186 26 77 163 164 49 180 219 71 60 51 6 153 226 123 72 154 108 218
37 50 1 84 90 216 199 53 10 51 50 112 92 140 146 32 34 216 92 88 2 27 35 110 103 123 14 36 85 250 238 108 175 212 31 253 203 237 252 38
186 93 22 42 241 233 240 19 6 1 135 63 216 27 244 242 234 225 172 60 202 29 162 209 45 48 50 2 25 114 16 193 49 18 223 6 92 226 247 152
7 52 3 64 158 201 131 133 244 252 137 177 48 12 212 32 80 155 115 46 69 104 164 229 73 85 47 20 43 109 127 157 74 198 173 230 80 81 77 89
52 157 7 85 253 86 36 188 136 153 153 217 240 216 10 220 82 128 206 131 3 132 187 146 154 129 173 249 241 223 194 181 34 119 223 47 12 3 120 175
79 248 87 79 141 253 81 183 218 242 193 142 225 128 43 194 89 249 91 113 156 9 6 225 67 81 62 247 53 240 54 233 203 167 43 45 89 87 38 191
139 236 151 143 164 112 20 19 46 27 245 112 95 111 228 78 41 202 219 223 46 51 0 87 22 93 206 164 184 244 227 156 65 85 196 12 39 10 38 211
204 6 40 128 152 29 83 46 202 117 5 182 176 253 39 35 178 54 196 62 92 208 132 41 120 55 154 34 104 253 99 105 140 31 192 187 27 121 250 170
112 151 190 147 230 92 201 191 166 248 147 40 120 158 197 26 157 180 66 205 96 164 166 202 85 140 163 189 45 57 100 208 8 45 220 97 122 92 187 79
19 235 223 178 38 129 247 230 75 205 34 201 225 86 107 188 195 222 57 209 209 29 117 39 137 150 179 210 135 220 201 87 59 66 14 230 125 107 69 215
128 238 197 217 149 64 76 132 85 73 113 194 38 240 118 246 236 157 86 79 68 64 183 85 231 97 77 65 242 215 205 237 149 121 71 10 186 84 138 81
73 148 48 26 197 191 106 117 210 190 160 17 57 243 43 154 33 229 19 97 121 124 148 187 205 157 31 228 139 110 77 43 227 234 153 106 37 84 195 95
105 171 209 97 188 215 172 152 250 234 104 67 10 36 190 3 10 28 163 200 182 80 230 38 136 196 67 194 36 234 231 236 208 214 138 112 219 50 161 115
35 110 94 87 17 149 240 187 223 184 156 48 252 243 43 13 122 214 98 93 13 69 47 71 19 12 20 83 31 32 69 77 95 251 5 50 179 115 22 104
144 58 242 80 215 234 31 8 220 168 129 223 119 88 142 201 43 128 151 32 164 73 209 241 222 162 16 196 207 5 200 198 155 249 138 206 115 56 176 7
192 241 134 145 232 209 129 59 165 109 163 35 191 115 10 193 94 52 28 2 156 95 47 234 252 128 169 37 145 175 244 123 31 122 48 90 208 18 199 48
30 155 143 133 138 228 122 76 0 216 17 161 128 159 70 128 98 233 124 98 111 43 12 110 112 126 185 230 2 254 115 1 184 188 252 154 244 87 24 251
246 230 251 113 82 63 122 176 177 13 143 199 184 66 180 221 86 138 5 204 70 44 78 205 175 57 231 112 250 16 27 57 0 96 72 15 231 113 220 142
96 219 38 213 82 125 36 56 146 138 21 184 89 206 248 215 129 133 61 173 68 178 44 242 135 198 95 140 30 73 4 135 133 243 168 75 126 161 230 144
77 148 87 166 0 213 254 109 133 197 23 176 116 139 183 177 14 247 103 168 2 179 58 189 65 224 241 240 51 117 227 95 151 93 246 82 50 31 36 146
54 44 18 64 95 15 195 97 161 107 78 170 56 203 219 88 87 205 251 144 95 235 164 90 158 165 154 197 100 124 41 4 190 250 215 247 113 6 118 168
82 38 87 61 160 228 230 70 1 82 221 201 88 10 251 185 131 73 130 223 85 253 51 53 38 225 197 115 15 24 86 118 142 33 78 1 134 27 7 63
187 49 168 238 221 95 101 148 142 48 32 216 107 44 178 5 151 239 9 210 27 63 80 213 78 154 185 115 116 154 205 218 151 72 51 0 19 80 47 35
129 83 198 111 206 165 128 66 93 136 144 1 98 43 191 32 140 108 4 61 96 220 223 208 190 103 181 221 120 177 28 171 118 109 104 16 181 205 89 119
144 237 152 98 240 33 69 171 190 105 241 216 47 79 100 77 232 102 3 207 45 218 12 252 50 169 172 79 199 8 74 185 102 204 239 68 60 110 180 103
134 147 162 53 146 7 22 61 179 85 73 136 152 129 215 91 155 20 98 184 167 140 71 220 176 102 0 232 24 230 98 64 238 198 78 121 214 47 49 30
33 152 125 6 139 198 251 17 102 221 96 44 14 97 132 122 47 148 123 78 242 79 90 68 41 195 234 94 92 88 144 149 151 222 149 222 23 169 128 96
5 147 175 167 148 160 245 249 149 190 251 144 170 43 6 31 105 179 238 220 78 96 162 100 33 102 222 230 41 20 220 71 197 21 2 230 105 89 186 23
189 25 11 66 195 114 227 94 239 107 114 60 13 135 173 221 29 106 188 224 2 99 101 16 65 8 59 118 108 101 53 130 218 58 85 241 161 202 95 28
242 7 36 125 186 134 74 190 201 239 248 17 67 198 17 130 101 233 9 144 50 24 141 186 153 168 116 176 244 46 85 75 185 226 242 187 114 201 46 185
189 212 128 105 116 216 27 158 103 36 104 182 63 48 134 164 141 221 192 138 64 161 12 226 96 199 15 220 232 232 249 160 199 174 150 213 83 237 67 98
172 128 175 243 30 178 226 235 6 21 96 79 29 55 68 61 186 133 3 238 238 209 235 225 142 205 245 110 81 201 214 118 121 230 157 75 87 156 171 221
150 88 231 85 232 232 25 199 105 115 195 242 253 157 187 99 254 189 133 153 204 26 44 247 99 116 201 198 134 144 221 113 37 100 179 225 44 204 112 58
195 216 121 2 140 125 171 120 57 131 195 38 29 171 168 44 75 216 34 21 205 136 228 148 69 76 224 157 29 177 246 42 193 208 29 15 227 142 249 113
6 169 58 207 217 235 221 2 55 238 220 201 52 72 150 86 195 201 162 243 28 39 14 36 73 171 61 153 126 79 50 23 157 244 201 32 94 176 3 148
184 136 252 175 214 160 230 141 6 28 32 31 25 201 120 165 51 201 28 174 47 41 88 137 243 141 3 147 81 144 45 227 1 88 167 242 135 229 96 226
221 63 43 181 252 208 89 114 28 160 232 107 239 139 37 235 122 161 137 215 4 225 151 69 107 136 192 240 119 72 193 67 248 98 164 222 134 27 217 71
159 177 248 8 22 8 225 53 34 85 30 59 239 208 75 34 55 10 48 36 186 78 177 130 153 47 204 153 244 14 195 56 42 194 9 16 158 37 179 54
196 80 154 144 140 106 144 178 227 226 95 98 19 205 74 248 25 212 145 71 103 17 206 163 253 31 219 0 207 78 163 214 162 230 119 242 161 43 242 9
26 214 71 182 197 167 77 154 90 51 97 152 93 239 253 62 210 6 78 166 134 153 7 28 194 211 96 83 238 97 207 60 125 99 152 91 176 215 43 131
49 171 224 67 45 8 152 176 154 138 185 111 138 218 209 10 161 147 61 202 2 206 158 133 47 184 69 109 209 120 33 232 150 52 19 220 12 222 145 121
14 223 234 125 182 85 47 214 2 201 239 31 136 171 239 137 222 109 126 64 185 240 242 15 60 174 204 141 78 201 251 143 147 18 174 242 50 104 212 96
80 99 123 154 99 103 182 179 200 107 120 89 184 38 133 206 80 117 99 95 134 166 168 87 133 46 113 218 165 148 116 204 176 163 84 97 153 208 247 104
75 14 63 135 208 245 119 40 181 217 233 28 201 238 140 156 80 1 202 29 233 18 152 65 180 195 39 169 179 18 48 191 226 96 118 68 119 160 34 82
230 207 122 86 55 40 145 243 126 215 183 187 111 55 55 234 127 170 154 229 227 55 63 146 253 122 192 181 163 140 229 197 33 178 145 40 131 170 244 131
77 215 49 68 142 109 44 231 248 204 237 147 226 134 103 161 32 229 126 164 4 164 17 54 225 215 166 43 134 152 151 244 1 112 143 54 42 0 145 164
100 251 82 139 171 82 80 102 203 100 203 167 167 185 30 80 117 175 229 222 221 128 18 172 218 62 57 134 93 174 46 23 155 10 82 182 138 209 5 121
154 163 46 67 239 144 180 0 114 232 112 119 238 71 119 235 6 38 161 70 37 29 170 205 117 236 128 200 73 186 104 31 160 1 236 14 170 232 80 42
17 211 4 136 175 119 46 100 228 130 217 224 34 254 36 73 50 35 236 177 243 151 152 121 156 155 159 177 160 173 39 90 43 2 241 223 76 228 87 103
169 206 87 76 200 243 28 63 172 126 243 19 22 243 9 180 62 155 244 218 211 133 169 59 36 6 200 112 23 237 4 59 143 210 169 242 19 88 164 83
19 203 87 241 39 235 176 141 68 184 116 111 143 134 252 160 155 51 235 214 69 89 14 81 124 191 99 187 154 142 44 2 123 183 239 22 35 159 237 180
100 103 196 211 197 44 201 83 240 240 222 237 168 8 79 242 252 119 225 133 27 75 12 91 213 192 108 124 41 183 73 158 228 122 151 61 24 203 4 40
240 146 118 63 84 208 253 218 31 219 161 245 139 155 215 133 67 97 31 63 70 213 26 136 208 18 148 175 143 106 89 110 109 11 20 140 232 54 54 116
215 63 197 97 52 142 119 104 12 43 251 248 94 37 20 189 121 237 26 55 180 214 121 227 200 56 181 212 141 231 254 77 145 6 13 52 69 67 87 21
94 140 175 252 248 213 69 144 114 122 24 93 97 189 221 148 37 34 153 216 50 84 143 42 128 92 244 34 163 170 8 96 53 34 79 141 215 178 251 248
31 4 33 217 50 106 111 32 68 196 73 66 223 10 61 162 187 4 230 107 238 130 186 94 154 124 188 109 57 171 174 100 141 110 44 233 21 149 46 1
152 108 19 201 39 178 165 29 169 210 27 14 208 86 23 161 146 39 253 59 211 124 49 231 175 20 212 194 210 182 142 49 46 232 97 113 250 23 89 46
150 94 60 73 120 117 241 166 229 253 163 220 4 156 89 79 139 185 209 141 35 178 90 243 148 111 132 233 120 19 132 5 227 65 10 61 156 92 30 22
127 65 65 78 70 235 178 212 111 49 75 249 129 26 181 128 2 159 144 214 62 27 23 23 90 129 187 119 52 88 131 103 137 248 212 143 108 63 217 83
108 148 116 144 155 94 50 23 216 40 142 27 137 26 171 179 122 53 5 11 104 129 218 212 73 175 160 80 170 228 161 243 179 185 191 7 186 8 42 243
108 192 115 49 141 130 194 33 150 24 72 230 212 61 228 92 250 253 243 86 163 21 223 67 85 58 227 243 176 44 230 49 174 154 31 230 209 233 142 202
222 102 86 205 182 235 109 79 237 138 210 168 197 185 206 124 45 25 209 76 19 132 51 13 195 170 125 214 235 205 49 243 51 89 90 179 64 202 195 105
36 122 78 19 11 191 90 179 49 157 56 195 227 248 207 108 120 85 93 84 227 201 61 223 78 53 221 35 207 127 82 100 227 155 111 89 199 192 98 142
86 154 170 18 104 19 94 133 7 234 85 143 38 236 120 171 31 181 4 104 98 172 219 246 152 121 162 144 201 251 55 71 55 13 248 197 122 44 75 232
134 84 38 28 8 252 208 217 203 36 157 114 143 226 223 176 182 165 20 18 156 48 94 136 183 76 165 148 33 72 157 171 172 181 0 195 20 75 2 175
86 84 249 178 214 96 104 190 18 15 235 239 147 165 182 68 244 89 42 152 252 156 13 96 254 3 204 249 116 87 128 54 136 100 64 24 39 20 159 247
208 126 15 89 202 90 63 197 48 181 85 57 169 154 18 79 101 94 63 39 94 11 59 137 64 87 55 152 237 161 183 82 253 47 5 245 39 10 176 125
206 62 169 198 37 59 60 83 153 8 31 221 76 29 237 198 22 0 239 101 20 128 189 218 0 108 250 9 92 221 22 228 197 155 56 245 238 173 44 157
58 233 22 58 38 241 229 253 55 231 94 137 50 139 112 139 95 193 64 100 114 43 165 235 236 13 47 14 109 145 221 244 45 151 105 187 2 0 19 234
217 111 78 154 50 197 31 175 85 41 147 217 128 203 183 159 0 55 4 41 36 15 108 184 139 183 55 13 85 113 62 11 234 44 87 204 209 210 120 29
152 12 157 80 80 148 225 215 145 90 229 157 196 4 174 194 17 127 211 169 84 25 133 97 91 137 203 33 120 216 44 108 11 158 58 214 148 165 90 173
228 210 184 66 66 145 254 216 116 7 190 96 113 173 236 1 81 225 39 123 188 8 24 15 80 254 77 59 1 142 172 154 139 52 105 40 219 99 81 216
62 181 17 211 233 249 43 93 6 240 107 20 107 37 123 233 243 131 225 137 17 193 70 74 73 177 180 247 134 139 145 36 97 101 101 125 194 147 136 134
153 225 152 193 104 116 18 63 151 230 241 230 135 204 10 44 126 48 68 30 251 160 17 140 98 52 151 201 154 17 36 73 17 179 138 215 98 75 235 42
214 103 74 89 186 178 138 124 197 2 237 205 136 135 246 179 83 136 194 148 152 142 133 56 61 150 56 64 46 164 25 71 178 242 131 196 171 174 93 184
228 20 26 114 115 154 89 87 229 168 36 186 81 202 99 223 196 218 70 252 30 151 232 18 163 116 251 165 43 189 95 250 44 52 103 244 95 43 217 220
6 29 54 106 164 42 19 49 142 133 94 82 174 204 18 83 132 184 239 212 26 83 58 223 237 88 237 225 88 4 53 50 79 8 90 224 103 157 174 101
201 2 143 195 58 94 175 28 0 254 237 152 126 249 240 56 247 138 11 219 155 178 229 199 153 146 136 86 22 59 200 18 124 136 54 241 181 170 183 196
32 114 115 105 20 163 240 105 135 124 190 106 63 159 1 200 136 118 212 148 179 200 155 113 103 47 37 85 32 55 228 105 244 202 66 24 199 102 20 90
#include <iomanip>
#include "seal_api.h"
#include "util.h"
using namespace seal;
using namespace std;
string ciphertext_name;
string key_dir;
// bool decrypt(size_t poly_d, size_t p_modulus, int &sample_size, string &ciphertext_dir);
bool decrypt(int &sample_size, string &ciphertext_dir);
int main(int argc, char **argv)
{
if (argc != 4)
{
// cout << "[ERROR] please enter /full/path/to/file/to/decrypt full/path/key " << endl;
// cout << "[ERROR] please enter prefix_file_to_decrypt full/path/key /full/path/to/storage" << endl;
// cout << "[ERROR] please enter a ciphertext file path, sample size and secret key path" << endl;
return -1;
}
else
{
string dir = argv[1];
int sample_size = atol(argv[2]);
key_dir = argv[3];
bool result_str = decrypt(sample_size, dir);
cout << result_str << endl;
return 0;
}
}
bool decrypt(int &sample_size, string &ciphertext_dir)
{
struct decryptor_t decr;
init_operator_batching(decr, key_dir);
bool isContain = false;
if (sample_size <= decr.bcode->slot_count()/2)
{
Ciphertext cipher_matrix;
vector<int64_t> pod_matrix;
load_ciphertext(decr, cipher_matrix, ciphertext_dir);
pod_matrix = decrypt_ciphermatrix(decr, cipher_matrix);
// cout << pod_matrix.size() << endl;
int no_dual_vectors = (decr.bcode->slot_count() / 2) / (sample_size);
vector<int64_t> v1, v2;
for (size_t i = 0; i < no_dual_vectors * sample_size; i++)
{
v1.push_back(pod_matrix[i]);
v2.push_back(pod_matrix[(pod_matrix.size() / 2) + i]);
}
int64_t sum = 0;
if (isContain == false)
{
// cout << "1 : ";
for (size_t i = 0; i < v1.size(); i++)
{
// cout << v1[i];
if ((i + 1) % sample_size == 0)
{
// cout << endl;
if (i < v1.size() - 1)
{
// cout << ((i + 1) / 40) + 1 << " : ";
}
}
else
{
// cout << ", ";
}
if (v1[i] == 0)
{
sum = sum + 1;
}
else
{
sum = 0;
}
if (sum == sample_size)
{
isContain = true;
}
}
}
// cout << endl;
if (isContain == false)
{
sum = 0;
// cout << (v2.size() + 1) / 40 + 1 << " : ";
for (size_t i = 0; i < v2.size(); i++)
{
// cout << v2[i];
if ((i + 1) % sample_size == 0)
{
// cout << endl;
if (i < v2.size() - 1)
{
// cout << ((v2.size() + i + 1) / 40) + 1 << " : ";
}
}
else
{
// cout << ", ";
}
if (v2[i] == 0)
{
sum = sum + 1;
}
else
{
sum = 0;
}
if (sum == sample_size)
{
isContain = true;
}
}
}
}
else
{
// cout << endl << "Sample size is too large" << endl;
}
delete_operator_batching(decr);
return isContain;
}
#include <iomanip>
#include "seal_api.h"
#include "util.h"
using namespace seal;
using namespace std;
string ciphertext_name;
string key_dir;
// bool decrypt(size_t poly_d, size_t p_modulus, int &sample_size, string &ciphertext_dir);
bool decrypt(int &sample_size, string &ciphertext_dir);
int main(int argc, char **argv)
{
if (argc != 4)
{
// cout << "[ERROR] please enter /full/path/to/file/to/decrypt full/path/key " << endl;
// cout << "[ERROR] please enter prefix_file_to_decrypt full/path/key /full/path/to/storage" << endl;
// cout << "[ERROR] please enter a ciphertext file path, sample size and secret key path" << endl;
return -1;
}
else
{
string dir = argv[1];
int sample_size = atol(argv[2]);
key_dir = argv[3];
bool result_str = decrypt(sample_size, dir);
cout << result_str << endl;
return 0;
}
}
bool decrypt(int &sample_size, string &ciphertext_dir)
{
struct decryptor_t decr;
init_operator_batching(decr, key_dir);
bool isContain = false;
if (sample_size <= decr.bcode->slot_count()/2)
{
Ciphertext cipher_matrix;
vector<int64_t> pod_matrix;
load_ciphertext(decr, cipher_matrix, ciphertext_dir);
pod_matrix = decrypt_ciphermatrix(decr, cipher_matrix);
// cout << pod_matrix.size() << endl;
int no_dual_vectors = (decr.bcode->slot_count() / 2) / (sample_size);
vector<int64_t> v1, v2;
for (size_t i = 0; i < no_dual_vectors * sample_size; i++)
{
v1.push_back(pod_matrix[i]);
v2.push_back(pod_matrix[(pod_matrix.size() / 2) + i]);
}
int64_t sum = 0;
if (isContain == false)
{
// cout << "1 : ";
for (size_t i = 0; i < v1.size(); i++)
{
// cout << v1[i];
if ((i + 1) % sample_size == 0)
{
// cout << endl;
if (i < v1.size() - 1)
{
// cout << ((i + 1) / 40) + 1 << " : ";
}
}
else
{
// cout << ", ";
}
if (v1[i] == 0)
{
sum = sum + 1;
}
else
{
sum = 0;
}
if (sum == sample_size)
{
isContain = true;
}
}
}
// cout << endl;
if (isContain == false)
{
sum = 0;
// cout << (v2.size() + 1) / 40 + 1 << " : ";
for (size_t i = 0; i < v2.size(); i++)
{
// cout << v2[i];
if ((i + 1) % sample_size == 0)
{
// cout << endl;
if (i < v2.size() - 1)
{
// cout << ((v2.size() + i + 1) / 40) + 1 << " : ";
}
}
else
{
// cout << ", ";
}
if (v2[i] == 0)
{
sum = sum + 1;
}
else
{
sum = 0;
}
if (sum == sample_size)
{
isContain = true;
}
}
}
}
else
{
// cout << endl << "Sample size is too large" << endl;
}
delete_operator_batching(decr);
return isContain;
}
#include <iomanip>
#include "seal_api.h"
#include "util.h"
using namespace seal;
using namespace std;
string ciphertext_name;
string key_dir;
// vector<int64_t> decrypt(size_t poly_d, size_t p_modulus, int &sample_size, string &ciphertext_dir);
vector<int64_t> decrypt(int &sample_size, string &ciphertext_dir);
int main(int argc, char **argv)
{
if (argc != 4)
{
// cout << "[ERROR] please enter /full/path/to/file/to/decrypt full/path/key " << endl;
// cout << "[ERROR] please enter prefix_file_to_decrypt full/path/key /full/path/to/storage" << endl;
cout << "[ERROR] please enter a ciphertext file path, sample size and secret key path" << endl;
return -1;
}
else
{
string dir = argv[1];
int sample_size = atol(argv[2]);
key_dir = argv[3];
vector<int64_t> result = decrypt(sample_size, dir);
for (int i = 0; i < result.size(); ++i)
{
std::cout << result[i] << ' ';
}
std::cout << endl;
return 0;
}
}
vector<int64_t> decrypt(int &sample_size, string &ciphertext_dir)
{
struct decryptor_t decr;
init_operator_batching(decr, key_dir);
// init_operator_batching(2048, 4294967296, decr, key_dir);
// init_operator_batching(4096, 4294967296, decr, key_dir);
// init_operator_batching(8192, 4294967296, decr, key_dir);
// init_operator_batching(16384, 4294967296, decr, key_dir);
// init_operator_batching(32768, 4294967296, decr, key_dir);
vector<int64_t> v;
if (sample_size <= decr.bcode->slot_count()/2)
{
Ciphertext cipher_matrix;
vector<int64_t> pod_matrix;
load_ciphertext(decr, cipher_matrix, ciphertext_dir);
pod_matrix = decrypt_ciphermatrix(decr, cipher_matrix);
for (size_t i = 0; i < sample_size; i++)
{
v.push_back(pod_matrix[i]);
}
}
else
{
// cout << endl << "Sample size is too large" << endl;
}
delete_operator_batching(decr);
return v;
}
#include <iomanip>
#include "seal_api.h"
#include "util.h"
using namespace seal;
using namespace std;
string ciphertext_name;
string key_dir;
// vector<int64_t> decrypt(size_t poly_d, size_t p_modulus, int &sample_size, string &ciphertext_dir);
vector<int64_t> decrypt(int &sample_size, string &ciphertext_dir);
int main(int argc, char **argv)
{
if (argc != 4)
{
// cout << "[ERROR] please enter /full/path/to/file/to/decrypt full/path/key " << endl;
// cout << "[ERROR] please enter prefix_file_to_decrypt full/path/key /full/path/to/storage" << endl;
cout << "[ERROR] please enter a ciphertext file path, sample size and secret key path" << endl;
return -1;
}
else
{
string dir = argv[1];
int sample_size = atol(argv[2]);
key_dir = argv[3];
vector<int64_t> result = decrypt(sample_size, dir);
for (int i = 0; i < result.size(); ++i)
{
std::cout << result[i] << ' ';
}
std::cout << endl;
return 0;
}
}
vector<int64_t> decrypt(int &sample_size, string &ciphertext_dir)
{
struct decryptor_t decr;
init_operator_batching(decr, key_dir);
// init_operator_batching(2048, 4294967296, decr, key_dir);
// init_operator_batching(4096, 4294967296, decr, key_dir);
// init_operator_batching(8192, 4294967296, decr, key_dir);
// init_operator_batching(16384, 4294967296, decr, key_dir);
// init_operator_batching(32768, 4294967296, decr, key_dir);
vector<int64_t> v;
if (sample_size <= decr.bcode->slot_count()/2)
{
Ciphertext cipher_matrix;
vector<int64_t> pod_matrix;
load_ciphertext(decr, cipher_matrix, ciphertext_dir);
pod_matrix = decrypt_ciphermatrix(decr, cipher_matrix);
for (size_t i = 0; i < sample_size; i++)
{
v.push_back(pod_matrix[i]);
}
}
else
{
// cout << endl << "Sample size is too large" << endl;
}
delete_operator_batching(decr);
return v;
}
#include "seal_api.h"
using namespace seal;
using namespace std;
int main(int argc, char **argv)
{
if (argc != 6)
{
// cout << "[ERROR] please enter 1 plaintext values, prefix pathstorage(exists) " << endl;
cout << "[ERROR] please enter plaintext vector value (eg. 75 67 8 23 076 2 23), output ciphertext file name or "
"prefix, ciphertext output file directory, sample size and public key path"
<< endl;
return -1;
}
else
{
string plaintext = argv[1];
string ciphertext_name = argv[2];
string ciphertext_dir = argv[3];
int sample_size = atol(argv[4]);
string key_dir = argv[5];
struct encryptor_t encr;
init_operator_batching(encr, key_dir);
stringstream ss;
ss << plaintext;
vector<int64_t> pod_matrix;
int64_t x = 0;
while (ss >> x)
{
pod_matrix.push_back(x);
}
if (pod_matrix.size() <= encr.bcode->slot_count() / 2 && pod_matrix.size() <= sample_size)
{
Ciphertext encrypted_matrix;
init_ciphermatrix(encr, pod_matrix, encrypted_matrix);
save_ciphertext(encrypted_matrix, ciphertext_dir + "/" + ciphertext_name + ".ct");
delete_operator_batching(encr);
return 0;
}
else
{
delete_operator_batching(encr);
return -1;
}
// delete_operator_batching(encr);
// return 0;
}
}
#include "seal_api.h"
using namespace seal;
using namespace std;
int main(int argc, char **argv)
{
if (argc != 6)
{
// cout << "[ERROR] please enter 1 plaintext values, prefix pathstorage(exists) " << endl;
cout << "[ERROR] please enter plaintext vector value (eg. 75 67 8 23 076 2 23), output ciphertext file name or "
"prefix, ciphertext output file directory, sample size and public key path"
<< endl;
return -1;
}
else
{
string plaintext = argv[1];
string ciphertext_name = argv[2];
string ciphertext_dir = argv[3];
int sample_size = atol(argv[4]);
string key_dir = argv[5];
struct encryptor_t encr;
init_operator_batching(encr, key_dir);
stringstream ss;
ss << plaintext;
vector<int64_t> pod_matrix;
int64_t x = 0;
while (ss >> x)
{
pod_matrix.push_back(x);
}
if (pod_matrix.size() <= encr.bcode->slot_count() / 2 && pod_matrix.size() <= sample_size)
{
Ciphertext encrypted_matrix;
init_ciphermatrix(encr, pod_matrix, encrypted_matrix);
save_ciphertext(encrypted_matrix, ciphertext_dir + "/" + ciphertext_name + ".ct");
delete_operator_batching(encr);
return 0;
}
else
{
delete_operator_batching(encr);
return -1;
}
// delete_operator_batching(encr);
// return 0;
}
}
#include <iostream>
#include "seal_api.h"
#include "util.h"
// #include <algorithm>
// #include <iterator>
// #include <vector>
// #include <filesystem>
using namespace seal;
using namespace std;
void sub_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2, Ciphertext &ct_out);
void add_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2, Ciphertext &ct_out);
void multiply_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2, Ciphertext &ct_out);
bool is_number(const string &s);
void printStrVector(const vector<string> &v);
vector<vector<string>> split_ends(const vector<string> &data, const vector<int> &ends);
void multiply_ciphertexts(struct evaluator_t &op_st, vector<Ciphertext> &cts, Ciphertext &ct_out);
void relinearize_inplace(struct evaluator_t &op_st, Ciphertext &ct);
void rescale_to_next_inplace(struct evaluator_t &op_st, Ciphertext &ct);
void multiply_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2);
void relinearize(struct evaluator_t &op_st, Ciphertext &ct, Ciphertext &ct_out);
void sub_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2);
void negate_inplace__ciphertext(struct evaluator_t &op_st, Ciphertext &ct);
void add_plain_inplace_ciphertext(struct evaluator_t &op_st, struct Ciphertext &ct, const Plaintext &plain);
void multiply_plain_inplace(struct evaluator_t &op_st, Ciphertext &ct, const Plaintext &plain);
void add_many_ciphertext(struct evaluator_t &op_st, vector<Ciphertext> &cts, Ciphertext &ct_out);
void exponentiate_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct, uint64_t &exponent);
void sub_plain_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct, const Plaintext &plain);
void mod_switch_to_next_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct);
int simpleCheck(
string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size, string &key_dir);
int checkSq(
string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size, string &key_dir);
Ciphertext check(
string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size, string &key_dir,
struct encryptor_t &encr, struct evaluator_t &eval);
// string relink_key_path;
// string galois_key_path;
// string public_key_path;
string key_dir = "";
int main(int argc, char **argv)
{
// input processing - begin
// string result_name = argv[argc - 6];
// string result_dir = argv[argc - 5];
// int sample_size = atoi(argv[argc - 4]);
// relink_key_path = argv[argc - 3];
// galois_key_path = argv[argc - 2];
// public_key_path = argv[argc - 1];
string source = argv[1];
string result_name = argv[argc - 4];
string result_dir = argv[argc - 3];
int sample_size = atoi(argv[argc - 2]);
key_dir = argv[argc - 1];
vector<string> data;
for (int i = 2; i < argc - 4; i++)
{
data.push_back(argv[i]);
}
// if (source == "" || data.size() == 0 || result_name == "" || result_dir == "" || sample_size == 0 ||
// relink_key_path == "" || galois_key_path == "" || public_key_path == "")
if (source == "" || data.size() == 0 || result_name == "" || result_dir == "" || sample_size == 0 || key_dir == "")
{
// error handling
cout << "[ERROR] please enter a source path, data paths, output ciphertext file name or prefix, output "
"ciphertext directory, sample size, linking key path, galois key path and public key path"
<< endl;
return -1;
}
// input processing - end
// simple algo
// int result = simpleCheck(source, data, result_name, result_dir, sample_size, key_dir);
// sequence algo
int result = checkSq(source, data, result_name, result_dir, sample_size, key_dir);
// error handling
if (result == -1)
{
fprintf(stderr, "error!\n");
}
else
{
cout << "done";
}
// checkSq(source, data, result_name, result_dir, sample_size, relink_key_path, galois_key_path, public_key_path);
return result;
}
int simpleCheck(
string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size, string &key_dir)
{
struct evaluator_t eval;
init_operator_batching(eval, key_dir);
struct encryptor_t encr;
init_operator_batching(encr, key_dir);
// cout << sample_size*data.size() << endl;
// cout << encr.bcode->slot_count() << endl;
if (sample_size * data.size() > encr.bcode->slot_count() || sample_size > encr.bcode->slot_count() / 2)
{
// error handling
delete_operator_batching(encr);
delete_operator_batching(eval);
return -1;
}
else
{
Ciphertext encrypted_result_matrix;
vector<int64_t> result_matrix;
init_ciphermatrix(encr, result_matrix, encrypted_result_matrix);
vector<int64_t> dummy_matrix;
for (size_t i = 0; i < sample_size; i++)
{
dummy_matrix.push_back(1);
}
Ciphertext encrypted_dummy_matrix;
init_ciphermatrix(encr, dummy_matrix, encrypted_dummy_matrix);
// normalize input data if its size is odd
int normalized_data_size;
if (data.size() % 2 == 0)
{
normalized_data_size = data.size();
}
else
{
normalized_data_size = data.size() + 1;
}
int required_range = normalized_data_size * sample_size;
int required_no_row_elements = required_range / 2;
int required_range_row = required_range / 2;
// create padding matrix
int padding_slots = (encr.bcode->slot_count() / 2) - required_range_row;
vector<int64_t> padding_matrix(encr.bcode->slot_count(), 0ULL);
for (size_t i = 0; i < padding_slots; i++)
{
padding_matrix[required_no_row_elements + i] = 1;
padding_matrix[encr.bcode->slot_count() - i] = 1;
}
Ciphertext encrypted_padding_matrix;
init_ciphermatrix(encr, padding_matrix, encrypted_padding_matrix);
if (required_range_row <= encr.bcode->slot_count() && required_range_row > 0)
{
for (int index = 0; index < normalized_data_size / 2; index++)
{
Ciphertext ct1, ct2, ct3;
Ciphertext temp1, temp2;
// cout << "[INFO] loading ciphertext 1" << endl;
load_ciphertext(eval, ct1, source);
// cout << "[INFO] loading ciphertext 2" << endl;
load_ciphertext(eval, ct2, data.at(index));
sub_ciphertext(eval, ct1, ct2, temp1);
if ((normalized_data_size / 2) + index < data.size())
{
// cout << "[INFO] loading ciphertext 3" << endl;
load_ciphertext(eval, ct3, data.at((normalized_data_size / 2) + index));
sub_ciphertext(eval, ct1, ct3, temp2);
}
else
{
// add dummy vector for oddy data
temp2 = encrypted_dummy_matrix;
}
eval.eval->rotate_columns_inplace(temp2, eval.gk);
add_ciphertext(eval, temp1, temp2, temp1);
add_ciphertext(eval, temp1, encrypted_result_matrix, encrypted_result_matrix);
// avoid the last shift
if (index + 1 != (normalized_data_size / 2))
{
eval.eval->rotate_rows_inplace(encrypted_result_matrix, -sample_size, eval.gk);
}
}
// add renmaining padding slots
add_ciphertext(eval, encrypted_result_matrix, encrypted_padding_matrix, encrypted_result_matrix);
}
save_ciphertext(encrypted_result_matrix, result_dir + "/" + result_name + ".ct");
delete_operator_batching(encr);
delete_operator_batching(eval);
return 0;
}
}
// int checkSq(
// string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size,
// string &relink_key_path, string &galois_key_path, string &public_key_path)
int checkSq(
string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size, string &key_dir)
{
struct evaluator_t eval;
// init_operator_batching(2048, 4294967296, eval, relink_key_path, galois_key_path);
// init_operator_batching(4096, 4294967296, eval, relink_key_path, galois_key_path);
// init_operator_batching(8192, 4294967296, eval, relink_key_path, galois_key_path);
// init_operator_batching(16384, 4294967296, eval, relink_key_path, galois_key_path);
// init_operator_batching(32768, 4294967296, eval, relink_key_path, galois_key_path);
init_operator_batching(eval, key_dir);
struct encryptor_t encr;
// init_operator_batching(4096, 4294967296, encr, public_key_path);
// init_operator_batching(8192, 4294967296, encr, public_key_path);
// init_operator_batching(16384, 4294967296, encr, public_key_path);
// init_operator_batching(32768, 4294967296, encr, public_key_path);
init_operator_batching(encr, key_dir);
// if (sample_size*data.size() > encr.bcode->slot_count() || sample_size > encr.bcode->slot_count()/2)
if (sample_size > encr.bcode->slot_count() / 2)
{
// error handling
delete_operator_batching(encr);
delete_operator_batching(eval);
return -1;
}
else
{
// struct evaluator_t eval;
// // init_operator_batching(2048, 4294967296, eval, relink_key_path, galois_key_path);
// // init_operator_batching(4096, 4294967296, eval, relink_key_path, galois_key_path);
// init_operator_batching(8192, 4294967296, eval, relink_key_path, galois_key_path);
// // init_operator_batching(16384, 4294967296, eval, relink_key_path, galois_key_path);
// // init_operator_batching(32768, 4294967296, eval, relink_key_path, galois_key_path);
// struct encryptor_t encr;
// // init_operator_batching(4096, 4294967296, encr, public_key_path);
// init_operator_batching(8192, 4294967296, encr, public_key_path);
// // init_operator_batching(16384, 4294967296, encr, public_key_path);
// // init_operator_batching(32768, 4294967296, encr, public_key_path);
int capacity = (encr.bcode->slot_count()) / sample_size;
// cout << capacity << endl;
// vector<string> v_temp;
// vector<string> v_v_temp;
// Ciphertext result;
vector<Ciphertext> v_result;
int nSq = data.size() / capacity;
for (size_t i = 0; i < nSq; i++)
{
Ciphertext result;
// cout << "sq : " << i << endl;
vector<string> v_temp;
for (size_t j = 0; j < capacity; j++)
{
string str = data.back();
v_temp.push_back(str);
data.pop_back();
}
if (i == 0)
{
// cout << "sq : init" << endl;
// result = check(
// source, v_temp, result_name, result_dir, sample_size, relink_key_path, galois_key_path,
// public_key_path, encr, eval);
result = check(source, v_temp, result_name, result_dir, sample_size, key_dir, encr, eval);
v_result.push_back(result);
}
else
{
// cout << "sq : other" << endl;
// Ciphertext result2 = check(
// source, v_temp, result_name, result_dir, sample_size, relink_key_path, galois_key_path,
// public_key_path, encr, eval);
// multiply_ciphertext(eval, result2, result, result);
// relinearize_inplace(eval, result);
// result = check(
// source, v_temp, result_name, result_dir, sample_size, relink_key_path, galois_key_path,
// public_key_path, encr, eval);
result = check(source, v_temp, result_name, result_dir, sample_size, key_dir, encr, eval);
v_result.push_back(result);
}
}
if (data.size() % capacity != 0)
{
// cout << "oddy!!! " << endl;
// Ciphertext result = check(
// source, data, result_name, result_dir, sample_size, relink_key_path, galois_key_path,
// public_key_path, encr, eval);
Ciphertext result = check(source, data, result_name, result_dir, sample_size, key_dir, encr, eval);
// multiply_ciphertext(eval, result2, result, result);
// relinearize_inplace(eval, result);
v_result.push_back(result);
}
Ciphertext result;
multiply_ciphertexts(eval, v_result, result);
relinearize_inplace(eval, result);
save_ciphertext(result, result_dir + "/" + result_name + ".ct");
delete_operator_batching(encr);
delete_operator_batching(eval);
return 0;
}
}
// Ciphertext check(
// string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size,
// string &relink_key_path, string &galois_key_path, string &public_key_path, struct encryptor_t &encr,
// struct evaluator_t &eval)
Ciphertext check(
string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size, string &key_dir,
struct encryptor_t &encr, struct evaluator_t &eval)
{
// if (source == "" || data.size() == 0 || result_name == "" || result_dir == "" || sample_size == 0)
// {
// // error handling
// // return -1;
// }
// else
// {
Ciphertext encrypted_result_matrix;
vector<int64_t> result_matrix;
init_ciphermatrix(encr, result_matrix, encrypted_result_matrix);
vector<int64_t> dummy_matrix;
for (size_t i = 0; i < sample_size; i++)
{
dummy_matrix.push_back(1);
}
Ciphertext encrypted_dummy_matrix;
init_ciphermatrix(encr, dummy_matrix, encrypted_dummy_matrix);
// normalize input data if its size is odd
int normalized_data_size;
if (data.size() % 2 == 0)
{
normalized_data_size = data.size();
}
else
{
normalized_data_size = data.size() + 1;
}
int required_range = normalized_data_size * sample_size;
int required_no_row_elements = required_range / 2;
int required_range_row = required_range / 2;
// create padding matrix
int padding_slots = (encr.bcode->slot_count() / 2) - required_range_row;
vector<int64_t> padding_matrix(encr.bcode->slot_count(), 0ULL);
for (size_t i = 0; i < padding_slots; i++)
{
padding_matrix[required_no_row_elements + i] = 1;
padding_matrix[(encr.bcode->slot_count() - 1) - i] = 1;
}
Ciphertext encrypted_padding_matrix;
init_ciphermatrix(encr, padding_matrix, encrypted_padding_matrix);
if (required_range_row <= encr.bcode->slot_count() && required_range_row > 0)
{
for (int index = 0; index < normalized_data_size / 2; index++)
{
Ciphertext ct1, ct2, ct3;
Ciphertext temp1, temp2;
// cout << "[INFO] loading ciphertext 1" << endl;
load_ciphertext(eval, ct1, source);
// cout << "[INFO] loading ciphertext 2" << endl;
load_ciphertext(eval, ct2, data.at(index));
sub_ciphertext(eval, ct1, ct2, temp1);
if ((normalized_data_size / 2) + index < data.size())
{
// cout << "[INFO] loading ciphertext 3" << endl;
load_ciphertext(eval, ct3, data.at((normalized_data_size / 2) + index));
sub_ciphertext(eval, ct1, ct3, temp2);
}
else
{
// add dummy vector for oddy data
temp2 = encrypted_dummy_matrix;
}
eval.eval->rotate_columns_inplace(temp2, eval.gk);
add_ciphertext(eval, temp1, temp2, temp1);
add_ciphertext(eval, temp1, encrypted_result_matrix, encrypted_result_matrix);
// avoid the last shift
if (index + 1 != (normalized_data_size / 2))
{
eval.eval->rotate_rows_inplace(encrypted_result_matrix, -sample_size, eval.gk);
}
}
// add renmaining padding slots
add_ciphertext(eval, encrypted_result_matrix, encrypted_padding_matrix, encrypted_result_matrix);
}
// // save_ciphertext(encrypted_result_matrix, result_dir + "/" + result_name + ".ct");
// delete_operator_batching(eval);
return encrypted_result_matrix;
// }
}
void sub_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2, Ciphertext &ct_out)
{
op_st.eval->sub(ct1, ct2, ct_out);
}
void sub_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2)
{
op_st.eval->sub_inplace(ct1, ct2);
}
void sub_plain_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct, const Plaintext &plain)
{
op_st.eval->sub_plain_inplace(ct, plain);
}
void negate_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct)
{
op_st.eval->negate_inplace(ct);
}
void add_plain_inplace_ciphertext(struct evaluator_t &op_st, struct Ciphertext &ct, const Plaintext &plain)
{
op_st.eval->add_plain_inplace(ct, plain);
}
void add_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2, Ciphertext &ct_out)
{
op_st.eval->add(ct1, ct2, ct_out);
}
void add_many_ciphertext(struct evaluator_t &op_st, vector<Ciphertext> &cts, Ciphertext &ct_out)
{
op_st.eval->add_many(cts, ct_out);
}
void multiply_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2, Ciphertext &ct_out)
{
op_st.eval->multiply(ct1, ct2, ct_out);
}
void multiply_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2)
{
op_st.eval->multiply_inplace(ct1, ct2);
}
void multiply_ciphertexts(struct evaluator_t &op_st, vector<Ciphertext> &cts, Ciphertext &ct_out)
{
op_st.eval->multiply_many(cts, op_st.lk, ct_out);
}
void multiply_plain_inplace(struct evaluator_t &op_st, Ciphertext &ct, const Plaintext &plain)
{
op_st.eval->multiply_plain_inplace(ct, plain);
}
void relinearize_inplace(struct evaluator_t &op_st, Ciphertext &ct)
{
op_st.eval->relinearize_inplace(ct, op_st.lk);
}
void relinearize(struct evaluator_t &op_st, Ciphertext &ct, Ciphertext &ct_out)
{
op_st.eval->relinearize(ct, op_st.lk, ct_out);
}
void rescale_to_next_inplace(struct evaluator_t &op_st, Ciphertext &ct)
{
op_st.eval->rescale_to_next_inplace(ct);
}
void exponentiate_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct, uint64_t &exponent)
{
op_st.eval->exponentiate_inplace(ct, exponent, op_st.lk);
}
void mod_switch_to_next_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct)
{
op_st.eval->mod_switch_to_next_inplace(ct);
}
#include <iostream>
#include "seal_api.h"
#include "util.h"
// #include <algorithm>
// #include <iterator>
// #include <vector>
// #include <filesystem>
using namespace seal;
using namespace std;
void sub_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2, Ciphertext &ct_out);
void add_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2, Ciphertext &ct_out);
void multiply_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2, Ciphertext &ct_out);
bool is_number(const string &s);
void printStrVector(const vector<string> &v);
vector<vector<string>> split_ends(const vector<string> &data, const vector<int> &ends);
void multiply_ciphertexts(struct evaluator_t &op_st, vector<Ciphertext> &cts, Ciphertext &ct_out);
void relinearize_inplace(struct evaluator_t &op_st, Ciphertext &ct);
void rescale_to_next_inplace(struct evaluator_t &op_st, Ciphertext &ct);
void multiply_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2);
void relinearize(struct evaluator_t &op_st, Ciphertext &ct, Ciphertext &ct_out);
void sub_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2);
void negate_inplace__ciphertext(struct evaluator_t &op_st, Ciphertext &ct);
void add_plain_inplace_ciphertext(struct evaluator_t &op_st, struct Ciphertext &ct, const Plaintext &plain);
void multiply_plain_inplace(struct evaluator_t &op_st, Ciphertext &ct, const Plaintext &plain);
void add_many_ciphertext(struct evaluator_t &op_st, vector<Ciphertext> &cts, Ciphertext &ct_out);
void exponentiate_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct, uint64_t &exponent);
void sub_plain_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct, const Plaintext &plain);
void mod_switch_to_next_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct);
int simpleCheck(
string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size, string &key_dir);
int checkSq(
string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size, string &key_dir);
Ciphertext check(
string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size, string &key_dir,
struct encryptor_t &encr, struct evaluator_t &eval);
// string relink_key_path;
// string galois_key_path;
// string public_key_path;
string key_dir = "";
int main(int argc, char **argv)
{
// input processing - begin
// string result_name = argv[argc - 6];
// string result_dir = argv[argc - 5];
// int sample_size = atoi(argv[argc - 4]);
// relink_key_path = argv[argc - 3];
// galois_key_path = argv[argc - 2];
// public_key_path = argv[argc - 1];
string source = argv[1];
string result_name = argv[argc - 4];
string result_dir = argv[argc - 3];
int sample_size = atoi(argv[argc - 2]);
key_dir = argv[argc - 1];
vector<string> data;
for (int i = 2; i < argc - 4; i++)
{
data.push_back(argv[i]);
}
// if (source == "" || data.size() == 0 || result_name == "" || result_dir == "" || sample_size == 0 ||
// relink_key_path == "" || galois_key_path == "" || public_key_path == "")
if (source == "" || data.size() == 0 || result_name == "" || result_dir == "" || sample_size == 0 || key_dir == "")
{
// error handling
cout << "[ERROR] please enter a source path, data paths, output ciphertext file name or prefix, output "
"ciphertext directory, sample size, linking key path, galois key path and public key path"
<< endl;
return -1;
}
// input processing - end
// simple algo
// int result = simpleCheck(source, data, result_name, result_dir, sample_size, key_dir);
// sequence algo
int result = checkSq(source, data, result_name, result_dir, sample_size, key_dir);
// error handling
if (result == -1)
{
fprintf(stderr, "error!\n");
}
else
{
cout << "done";
}
// checkSq(source, data, result_name, result_dir, sample_size, relink_key_path, galois_key_path, public_key_path);
return result;
}
int simpleCheck(
string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size, string &key_dir)
{
struct evaluator_t eval;
init_operator_batching(eval, key_dir);
struct encryptor_t encr;
init_operator_batching(encr, key_dir);
// cout << sample_size*data.size() << endl;
// cout << encr.bcode->slot_count() << endl;
if (sample_size * data.size() > encr.bcode->slot_count() || sample_size > encr.bcode->slot_count() / 2)
{
// error handling
delete_operator_batching(encr);
delete_operator_batching(eval);
return -1;
}
else
{
Ciphertext encrypted_result_matrix;
vector<int64_t> result_matrix;
init_ciphermatrix(encr, result_matrix, encrypted_result_matrix);
vector<int64_t> dummy_matrix;
for (size_t i = 0; i < sample_size; i++)
{
dummy_matrix.push_back(1);
}
Ciphertext encrypted_dummy_matrix;
init_ciphermatrix(encr, dummy_matrix, encrypted_dummy_matrix);
// normalize input data if its size is odd
int normalized_data_size;
if (data.size() % 2 == 0)
{
normalized_data_size = data.size();
}
else
{
normalized_data_size = data.size() + 1;
}
int required_range = normalized_data_size * sample_size;
int required_no_row_elements = required_range / 2;
int required_range_row = required_range / 2;
// create padding matrix
int padding_slots = (encr.bcode->slot_count() / 2) - required_range_row;
vector<int64_t> padding_matrix(encr.bcode->slot_count(), 0ULL);
for (size_t i = 0; i < padding_slots; i++)
{
padding_matrix[required_no_row_elements + i] = 1;
padding_matrix[encr.bcode->slot_count() - i] = 1;
}
Ciphertext encrypted_padding_matrix;
init_ciphermatrix(encr, padding_matrix, encrypted_padding_matrix);
if (required_range_row <= encr.bcode->slot_count() && required_range_row > 0)
{
for (int index = 0; index < normalized_data_size / 2; index++)
{
Ciphertext ct1, ct2, ct3;
Ciphertext temp1, temp2;
// cout << "[INFO] loading ciphertext 1" << endl;
load_ciphertext(eval, ct1, source);
// cout << "[INFO] loading ciphertext 2" << endl;
load_ciphertext(eval, ct2, data.at(index));
sub_ciphertext(eval, ct1, ct2, temp1);
if ((normalized_data_size / 2) + index < data.size())
{
// cout << "[INFO] loading ciphertext 3" << endl;
load_ciphertext(eval, ct3, data.at((normalized_data_size / 2) + index));
sub_ciphertext(eval, ct1, ct3, temp2);
}
else
{
// add dummy vector for oddy data
temp2 = encrypted_dummy_matrix;
}
eval.eval->rotate_columns_inplace(temp2, eval.gk);
add_ciphertext(eval, temp1, temp2, temp1);
add_ciphertext(eval, temp1, encrypted_result_matrix, encrypted_result_matrix);
// avoid the last shift
if (index + 1 != (normalized_data_size / 2))
{
eval.eval->rotate_rows_inplace(encrypted_result_matrix, -sample_size, eval.gk);
}
}
// add renmaining padding slots
add_ciphertext(eval, encrypted_result_matrix, encrypted_padding_matrix, encrypted_result_matrix);
}
save_ciphertext(encrypted_result_matrix, result_dir + "/" + result_name + ".ct");
delete_operator_batching(encr);
delete_operator_batching(eval);
return 0;
}
}
// int checkSq(
// string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size,
// string &relink_key_path, string &galois_key_path, string &public_key_path)
int checkSq(
string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size, string &key_dir)
{
struct evaluator_t eval;
// init_operator_batching(2048, 4294967296, eval, relink_key_path, galois_key_path);
// init_operator_batching(4096, 4294967296, eval, relink_key_path, galois_key_path);
// init_operator_batching(8192, 4294967296, eval, relink_key_path, galois_key_path);
// init_operator_batching(16384, 4294967296, eval, relink_key_path, galois_key_path);
// init_operator_batching(32768, 4294967296, eval, relink_key_path, galois_key_path);
init_operator_batching(eval, key_dir);
struct encryptor_t encr;
// init_operator_batching(4096, 4294967296, encr, public_key_path);
// init_operator_batching(8192, 4294967296, encr, public_key_path);
// init_operator_batching(16384, 4294967296, encr, public_key_path);
// init_operator_batching(32768, 4294967296, encr, public_key_path);
init_operator_batching(encr, key_dir);
// if (sample_size*data.size() > encr.bcode->slot_count() || sample_size > encr.bcode->slot_count()/2)
if (sample_size > encr.bcode->slot_count() / 2)
{
// error handling
delete_operator_batching(encr);
delete_operator_batching(eval);
return -1;
}
else
{
// struct evaluator_t eval;
// // init_operator_batching(2048, 4294967296, eval, relink_key_path, galois_key_path);
// // init_operator_batching(4096, 4294967296, eval, relink_key_path, galois_key_path);
// init_operator_batching(8192, 4294967296, eval, relink_key_path, galois_key_path);
// // init_operator_batching(16384, 4294967296, eval, relink_key_path, galois_key_path);
// // init_operator_batching(32768, 4294967296, eval, relink_key_path, galois_key_path);
// struct encryptor_t encr;
// // init_operator_batching(4096, 4294967296, encr, public_key_path);
// init_operator_batching(8192, 4294967296, encr, public_key_path);
// // init_operator_batching(16384, 4294967296, encr, public_key_path);
// // init_operator_batching(32768, 4294967296, encr, public_key_path);
int capacity = (encr.bcode->slot_count()) / sample_size;
// cout << capacity << endl;
// vector<string> v_temp;
// vector<string> v_v_temp;
// Ciphertext result;
vector<Ciphertext> v_result;
int nSq = data.size() / capacity;
for (size_t i = 0; i < nSq; i++)
{
Ciphertext result;
// cout << "sq : " << i << endl;
vector<string> v_temp;
for (size_t j = 0; j < capacity; j++)
{
string str = data.back();
v_temp.push_back(str);
data.pop_back();
}
if (i == 0)
{
// cout << "sq : init" << endl;
// result = check(
// source, v_temp, result_name, result_dir, sample_size, relink_key_path, galois_key_path,
// public_key_path, encr, eval);
result = check(source, v_temp, result_name, result_dir, sample_size, key_dir, encr, eval);
v_result.push_back(result);
}
else
{
// cout << "sq : other" << endl;
// Ciphertext result2 = check(
// source, v_temp, result_name, result_dir, sample_size, relink_key_path, galois_key_path,
// public_key_path, encr, eval);
// multiply_ciphertext(eval, result2, result, result);
// relinearize_inplace(eval, result);
// result = check(
// source, v_temp, result_name, result_dir, sample_size, relink_key_path, galois_key_path,
// public_key_path, encr, eval);
result = check(source, v_temp, result_name, result_dir, sample_size, key_dir, encr, eval);
v_result.push_back(result);
}
}
if (data.size() % capacity != 0)
{
// cout << "oddy!!! " << endl;
// Ciphertext result = check(
// source, data, result_name, result_dir, sample_size, relink_key_path, galois_key_path,
// public_key_path, encr, eval);
Ciphertext result = check(source, data, result_name, result_dir, sample_size, key_dir, encr, eval);
// multiply_ciphertext(eval, result2, result, result);
// relinearize_inplace(eval, result);
v_result.push_back(result);
}
Ciphertext result;
multiply_ciphertexts(eval, v_result, result);
relinearize_inplace(eval, result);
save_ciphertext(result, result_dir + "/" + result_name + ".ct");
delete_operator_batching(encr);
delete_operator_batching(eval);
return 0;
}
}
// Ciphertext check(
// string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size,
// string &relink_key_path, string &galois_key_path, string &public_key_path, struct encryptor_t &encr,
// struct evaluator_t &eval)
Ciphertext check(
string &source, vector<string> &data, string &result_name, string &result_dir, int &sample_size, string &key_dir,
struct encryptor_t &encr, struct evaluator_t &eval)
{
// if (source == "" || data.size() == 0 || result_name == "" || result_dir == "" || sample_size == 0)
// {
// // error handling
// // return -1;
// }
// else
// {
Ciphertext encrypted_result_matrix;
vector<int64_t> result_matrix;
init_ciphermatrix(encr, result_matrix, encrypted_result_matrix);
vector<int64_t> dummy_matrix;
for (size_t i = 0; i < sample_size; i++)
{
dummy_matrix.push_back(1);
}
Ciphertext encrypted_dummy_matrix;
init_ciphermatrix(encr, dummy_matrix, encrypted_dummy_matrix);
// normalize input data if its size is odd
int normalized_data_size;
if (data.size() % 2 == 0)
{
normalized_data_size = data.size();
}
else
{
normalized_data_size = data.size() + 1;
}
int required_range = normalized_data_size * sample_size;
int required_no_row_elements = required_range / 2;
int required_range_row = required_range / 2;
// create padding matrix
int padding_slots = (encr.bcode->slot_count() / 2) - required_range_row;
vector<int64_t> padding_matrix(encr.bcode->slot_count(), 0ULL);
for (size_t i = 0; i < padding_slots; i++)
{
padding_matrix[required_no_row_elements + i] = 1;
padding_matrix[(encr.bcode->slot_count() - 1) - i] = 1;
}
Ciphertext encrypted_padding_matrix;
init_ciphermatrix(encr, padding_matrix, encrypted_padding_matrix);
if (required_range_row <= encr.bcode->slot_count() && required_range_row > 0)
{
for (int index = 0; index < normalized_data_size / 2; index++)
{
Ciphertext ct1, ct2, ct3;
Ciphertext temp1, temp2;
// cout << "[INFO] loading ciphertext 1" << endl;
load_ciphertext(eval, ct1, source);
// cout << "[INFO] loading ciphertext 2" << endl;
load_ciphertext(eval, ct2, data.at(index));
sub_ciphertext(eval, ct1, ct2, temp1);
if ((normalized_data_size / 2) + index < data.size())
{
// cout << "[INFO] loading ciphertext 3" << endl;
load_ciphertext(eval, ct3, data.at((normalized_data_size / 2) + index));
sub_ciphertext(eval, ct1, ct3, temp2);
}
else
{
// add dummy vector for oddy data
temp2 = encrypted_dummy_matrix;
}
eval.eval->rotate_columns_inplace(temp2, eval.gk);
add_ciphertext(eval, temp1, temp2, temp1);
add_ciphertext(eval, temp1, encrypted_result_matrix, encrypted_result_matrix);
// avoid the last shift
if (index + 1 != (normalized_data_size / 2))
{
eval.eval->rotate_rows_inplace(encrypted_result_matrix, -sample_size, eval.gk);
}
}
// add renmaining padding slots
add_ciphertext(eval, encrypted_result_matrix, encrypted_padding_matrix, encrypted_result_matrix);
}
// // save_ciphertext(encrypted_result_matrix, result_dir + "/" + result_name + ".ct");
// delete_operator_batching(eval);
return encrypted_result_matrix;
// }
}
void sub_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2, Ciphertext &ct_out)
{
op_st.eval->sub(ct1, ct2, ct_out);
}
void sub_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2)
{
op_st.eval->sub_inplace(ct1, ct2);
}
void sub_plain_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct, const Plaintext &plain)
{
op_st.eval->sub_plain_inplace(ct, plain);
}
void negate_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct)
{
op_st.eval->negate_inplace(ct);
}
void add_plain_inplace_ciphertext(struct evaluator_t &op_st, struct Ciphertext &ct, const Plaintext &plain)
{
op_st.eval->add_plain_inplace(ct, plain);
}
void add_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2, Ciphertext &ct_out)
{
op_st.eval->add(ct1, ct2, ct_out);
}
void add_many_ciphertext(struct evaluator_t &op_st, vector<Ciphertext> &cts, Ciphertext &ct_out)
{
op_st.eval->add_many(cts, ct_out);
}
void multiply_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2, Ciphertext &ct_out)
{
op_st.eval->multiply(ct1, ct2, ct_out);
}
void multiply_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct1, Ciphertext &ct2)
{
op_st.eval->multiply_inplace(ct1, ct2);
}
void multiply_ciphertexts(struct evaluator_t &op_st, vector<Ciphertext> &cts, Ciphertext &ct_out)
{
op_st.eval->multiply_many(cts, op_st.lk, ct_out);
}
void multiply_plain_inplace(struct evaluator_t &op_st, Ciphertext &ct, const Plaintext &plain)
{
op_st.eval->multiply_plain_inplace(ct, plain);
}
void relinearize_inplace(struct evaluator_t &op_st, Ciphertext &ct)
{
op_st.eval->relinearize_inplace(ct, op_st.lk);
}
void relinearize(struct evaluator_t &op_st, Ciphertext &ct, Ciphertext &ct_out)
{
op_st.eval->relinearize(ct, op_st.lk, ct_out);
}
void rescale_to_next_inplace(struct evaluator_t &op_st, Ciphertext &ct)
{
op_st.eval->rescale_to_next_inplace(ct);
}
void exponentiate_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct, uint64_t &exponent)
{
op_st.eval->exponentiate_inplace(ct, exponent, op_st.lk);
}
void mod_switch_to_next_inplace_ciphertext(struct evaluator_t &op_st, Ciphertext &ct)
{
op_st.eval->mod_switch_to_next_inplace(ct);
}
#include "seal_api.h"
using namespace std;
using namespace seal;
int main(int argc, char **argv)
{
string key_dir = argv[1];
size_t poly_d = 4096;
// Params option 1
int bit_size = 20;
// Params option 2
// uint64_t plain_modulus = 1032193;
// vector<int> bit_sizes = { 36, 36, 37 };
// timeval t0, t1;
// unsigned long dt = 0;
// gettimeofday(&t0, NULL);
batching_generate_keys(poly_d, bit_size, key_dir, true);
// batching_generate_keys(poly_d, bit_sizes, plain_modulus, key_dir, true);
// gettimeofday(&t1, NULL);
// dt = 1000000 * (t1.tv_sec - t0.tv_sec) + (t1.tv_usec - t0.tv_usec);
// cout << "[INFO] keys generation time in seconds: " << ((float)dt)/1000000 << endl;
return 0;
}
#include "seal_api.h"
using namespace std;
using namespace seal;
int main(int argc, char **argv)
{
string key_dir = argv[1];
size_t poly_d = 4096;
// Params option 1
int bit_size = 20;
// Params option 2
// uint64_t plain_modulus = 1032193;
// vector<int> bit_sizes = { 36, 36, 37 };
// timeval t0, t1;
// unsigned long dt = 0;
// gettimeofday(&t0, NULL);
batching_generate_keys(poly_d, bit_size, key_dir, true);
// batching_generate_keys(poly_d, bit_sizes, plain_modulus, key_dir, true);
// gettimeofday(&t1, NULL);
// dt = 1000000 * (t1.tv_sec - t0.tv_sec) + (t1.tv_usec - t0.tv_usec);
// cout << "[INFO] keys generation time in seconds: " << ((float)dt)/1000000 << endl;
return 0;
}
/*
(C) Copyright 2022 CEA LIST. All Rights Reserved.
*/
#include "print_api.h"
using namespace std;
void print_vectors(vector<int64_t> &v)
{
for (int i = 0; i < (int)(v.size()); ++i)
cout << v[i] << " ";
cout << endl;
}
void print_vectors(vector<double> &v)
{
for (int i = 0; i < (int)(v.size()); ++i)
cout << v[i] << " ";
cout << endl;
}
void print_matrix(vector<vector<int64_t>> &m)
{
for (int i = 0; i < (int)(m.size()); ++i)
print_vectors(m[i]);
}
void print_matrix(vector<vector<double>> &m)
{
for (int i = 0; i < (int)(m.size()); ++i)
print_vectors(m[i]);
}
/*void rand_vector(int seed, uint64_t v_space, uint32_t v_size, vector<int64_t>& v)
{
srand(seed);
for (uint32_t i = 0; i < v_size; ++i)
v[i] = rand() % v_space;
}
*/
void rand_vector(int seed, uint64_t v_space, uint32_t v_size, vector<int64_t>& v)
{
std::uniform_real_distribution<double> unif(0, v_space);
std::default_random_engine re;
re.seed(seed);
for (uint32_t i = 0; i < v_size; ++i)
v[i] = (int64_t)unif(re) % v_space;
}
void rand_vector(int seed, uint64_t v_space, uint32_t v_size, vector<double>& v)
{
std::uniform_real_distribution<double> unif(0, v_space);
std::default_random_engine re;
re.seed(seed);
for (uint32_t i = 0; i < v_size; ++i)
v[i] = unif(re);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment