Spaces:
Running

Kast-KIIT commited on
Commit
291e33f
·
verified ·
1 Parent(s): 76b2e64

Can the signature be covered - Follow Up Deployment

Browse files
Files changed (1) hide show
  1. index.html +24 -17
index.html CHANGED
@@ -498,17 +498,26 @@
498
  updateCharCount();
499
  }
500
 
501
- // Generate a unique signature for the assignment
502
  function generateSignature() {
503
- const data = {
504
- rollNumber: displayRollNumber.textContent,
505
- studentName: displayStudentName.textContent,
506
- content: editor.getValue(),
507
- timestamp: new Date().toISOString()
508
- };
509
 
510
- // In a real app, this would be a more secure hash
511
- return btoa(JSON.stringify(data)).slice(0, 32);
 
 
 
 
 
 
 
 
 
 
 
 
512
  }
513
 
514
  // Verify assignment (teacher mode)
@@ -550,15 +559,13 @@
550
 
551
  // Generate verification signature
552
  function generateVerificationSignature(assignmentData) {
553
- // Must match the same logic as generateSignature()
554
- const data = {
555
- rollNumber: assignmentData.rollNumber,
556
- studentName: assignmentData.studentName,
557
- content: assignmentData.content,
558
- timestamp: assignmentData.timestamp
559
- };
560
 
561
- return btoa(JSON.stringify(data)).slice(0, 32);
 
 
562
  }
563
 
564
  // Show verification result
 
498
  updateCharCount();
499
  }
500
 
501
+ // Generate a secure signature for the assignment
502
  function generateSignature() {
503
+ const secretSalt = "EDU_SECURE_" + Math.floor(Date.now() / 1000 / 3600); // Changes hourly
504
+ const contentHash = hashCode(editor.getValue());
505
+ const studentHash = hashCode(displayRollNumber.textContent + displayStudentName.textContent);
 
 
 
506
 
507
+ // Combine with timestamp and hash everything
508
+ const combined = `${secretSalt}|${contentHash}|${studentHash}|${new Date().toISOString()}`;
509
+ return hashCode(combined).toString(16).slice(0, 32);
510
+ }
511
+
512
+ // Helper function to create simple hash
513
+ function hashCode(str) {
514
+ let hash = 0;
515
+ for (let i = 0; i < str.length; i++) {
516
+ const char = str.charCodeAt(i);
517
+ hash = ((hash << 5) - hash) + char;
518
+ hash |= 0; // Convert to 32bit integer
519
+ }
520
+ return hash;
521
  }
522
 
523
  // Verify assignment (teacher mode)
 
559
 
560
  // Generate verification signature
561
  function generateVerificationSignature(assignmentData) {
562
+ const secretSalt = "EDU_SECURE_" + Math.floor(new Date(assignmentData.timestamp).getTime() / 1000 / 3600);
563
+ const contentHash = hashCode(assignmentData.content);
564
+ const studentHash = hashCode(assignmentData.rollNumber + assignmentData.studentName);
 
 
 
 
565
 
566
+ // Combine with timestamp and hash everything
567
+ const combined = `${secretSalt}|${contentHash}|${studentHash}|${assignmentData.timestamp}`;
568
+ return hashCode(combined).toString(16).slice(0, 32);
569
  }
570
 
571
  // Show verification result