Secure Function Evaluation
Secure Function Evaluation (SFE) can be used to verify a value, without
releasing the original data. For example if we have a voting competion with Bob,
Alice and Carol. Bob, Alice and Carol vote, and they want to keep their votes
secret, but they need to calculate the overall total. Typically an independent
person would tally up the votes, but what if they do not trust anyone. This is
where SFE comes in, where they can calculate the total with knowing the votes
from the others. For example, press the first button to generate some votes:
Next Bob creates three random values which give a sum of (his vote+100) to give:
Next Alice creates three random values which give a sum of (her vote+100) to give:
Next Carol creates three random values which give a sum of (her vote+100) to give:
Bob gets Alice's second value, and Carol's second value, and adds it to his first
value and calculates the sum as:
Alice gets Bob's second value, and Carol's third value, and adds it to her first
value and calculates the sum as::
Carol gets Alice's third value, and Bob's third value, and adds it to her first
value and calculates the sum as:
Finally Bob, Alice and Carol announce their calculations, and it is added up to:
which taken with modulo 100 gives:
which should be the total of the votes!!!!! Check the original votes for Bob, Alice and Carol and make sure that it totals this value. So ... Bob, Alice and Carol know the total, but not any of votes of the others.
The code is:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Security.Cryptography;
using System.IO;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
int Bob;
int Alice;
int Carol;
int bob1, bob2, bob3;
int alice1, alice2, alice3;
int carol1, carol2, carol3;
int bobnew, alicenew, carolnew;
int result;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Random r = new Random();
Bob = (int)r.Next(1, 10);
Alice = (int)r.Next(1, 10);
Carol = (int)r.Next(1, 10);
TextBox1.Text = Bob.ToString();
TextBox2.Text = Alice.ToString();
TextBox3.Text = Carol.ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
Random r = new Random();
Bob = Convert.ToInt32(TextBox1.Text);
Alice = Convert.ToInt32(TextBox2.Text);
Carol = Convert.ToInt32(TextBox3.Text);
bob1 = (int)r.Next(1, Bob + 100);
bob2 = (int)r.Next(1, Bob + 100 - bob1);
bob3 = 100 + Bob - bob1 - bob2;
TextBox4.Text = bob1.ToString(); TextBox5.Text = bob2.ToString(); TextBox6.Text = bob3.ToString();
alice1 = (int)r.Next(1, Alice + 100);
alice2 = (int)r.Next(1, Alice + 100 - alice1);
alice3 = 100 + Alice - alice1 - alice2;
TextBox7.Text = alice1.ToString(); TextBox8.Text = alice2.ToString(); TextBox9.Text = alice3.ToString();
carol1 = (int)r.Next(1, Carol + 100);
carol2 = (int)r.Next(1, Carol + 100 - carol1);
carol3 = 100 + Carol - carol1 - carol2;
TextBox10.Text = carol1.ToString(); TextBox11.Text = carol2.ToString(); TextBox12.Text = carol3.ToString();
bobnew = bob1 + alice2 + carol2;
alicenew = alice1 + bob2 + carol3;
carolnew = carol1 + bob3 + alice3;
TextBox13.Text = bobnew.ToString();
TextBox14.Text = alicenew.ToString();
TextBox15.Text = carolnew.ToString();
result = (bobnew + alicenew + carolnew) ;
TextBox16.Text = result.ToString();
result = result % 100;
TextBox17.Text = result.ToString();
}
}
|